<?php
/**
 * 商品分类管理
 * $Id: product_category_edit_result.php,v 1.1 2015/10/08 11:18:46 wanggb Exp $
 * @author wanggb
 * @package manager.public_html
 */

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

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

// 权限检查
if (!checkAuthority("ADMIN,MANAGER,STAFF")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["footer"] = "footer.inc";
	$layout_pages["top"] = "menu.inc";
	$layout_pages["middle"] = "error.inc";
	$message = "权限不足，请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/topmenutopsub_layout.inc");
	exit;
}

// 参数取得
$mst_id = ParamUtil::getRequestNumber("mst_id", 0);
$dat_id = ParamUtil::getRequestNumber("dat_id", 0);
$subject_id = ParamUtil::getRequestNumber("subject_id", 0);
$action = ParamUtil::getRequestString("action");

//echo "mst_id=" . $mst_id . "<br />";
//echo "dat_id=" . $dat_id . "<br />";
//echo "subject_id=" . $subject_id . "<br />";
//echo "action=" . $action . "<br />";


//添加题目
if($action == "add") {
	$display_order = ExaminationHandler::getMaxDisplayorder();
	$subject_dat = SubjectDat::getById($subject_id);
	$examination_dat = new ExaminationDat();
	$examination_dat->examination_mst_id = $mst_id;
	$examination_dat->subject_id = $subject_id;
	$examination_dat->category_id = $subject_dat->category_id;
	$examination_dat->title = $subject_dat->title;
	$examination_dat->mp3 = $subject_dat->mp3;
	$examination_dat->selection1 = $subject_dat->selection1;
	$examination_dat->selection2 = $subject_dat->selection2;
	$examination_dat->selection3 = $subject_dat->selection3;
	$examination_dat->selection4 = $subject_dat->selection4;
	$examination_dat->comment = $subject_dat->comment;
	$examination_dat->right_answer = $subject_dat->right_answer;
	$examination_dat->point = $subject_dat->point;
	$examination_dat->display_order = $display_order + 1;
	$examination_dat->save();
}

//删除题目
if($action == "delete") {
	$examination_dat = ExaminationDat::getById($dat_id);
	$examination_dat->delete_flg = true;
	$examination_dat->save();
}


// 跳到一览页
header("Location:examination_dat_list.php?id=" . $mst_id);
exit;