<?php
require_once '../phpbean/ClassInfo.class.php';
require_once '../service/ClassInfoService.class.php';

//创建了ClassInfoService实例
$classInfoService = new ClassInfoService();

//根据action参数决定用户要执行什么样的操作
if(!empty($_REQUEST['action'])) {
	//接收action值
	$action = $_REQUEST['action'];
	if($action == "add") {
		//说明用户希望执行添加班级信息信息
		$classInfo = new ClassInfo();
		$array_classInfo = $_POST["classInfo"];
		$classInfo->setClassNumber($array_classInfo['classNumber']);
		$classInfo->setClassName($array_classInfo['className']);
		$classInfo->setClassSpecialFieldNumber($array_classInfo['classSpecialFieldNumber']);
		$classInfo->setClassBirthDate($array_classInfo['classBirthDate']);
		$classInfo->setClassTeacherCharge($array_classInfo['classTeacherCharge']);
		$classInfo->setClassTelephone($array_classInfo['classTelephone']);
		$classInfo->setClassMemo($array_classInfo['classMemo']);
		//完成添加->数据库
		$res = $classInfoService->AddClassInfo($classInfo);
		if($res==1) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "query") {
		//查询班级信息信息
		require_once '../service/ClassInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$classNumber = !empty($_POST['classNumber']) ? $_POST['classNumber'] : "";
		$className = !empty($_POST['className']) ? $_POST['className'] : "";
		$classSpecialFieldNumber = !empty($_POST['classSpecialFieldNumber']) ? $_POST['classSpecialFieldNumber'] : "";
		$classBirthDate = !empty($_POST['classBirthDate']) ? $_POST['classBirthDate'] : "";
		//创建ClassInfoService实例
		$classInfoService = new ClassInfoService();

		//创建一个FenyePage对象实例
		$fenyePage = new FenyePage();
		//给fenyePage指定必须的参数
		$fenyePage->pageNow = 1;
		$fenyePage->pageSize = 5;
		$fenyePage->gotoUrl = "ClassInfoAction.php";

		//在此我们需要根据用户的点击来修改pageNow的值，不要判断是否有这个pageNow发送
		if(!empty($_REQUEST['pageNow'])){
			$fenyePage->pageNow=$_REQUEST['pageNow'];
		}

		//调用getFenyePage，该方法可以把fenyePage完成
		$classInfoService->getFenyePage($fenyePage,$classNumber,$className,$classSpecialFieldNumber,$classBirthDate);
		require_once '../service/SpecialFieldInfoService.class.php';
		$specialFieldInfoService = new SpecialFieldInfoService();
		$specialFieldInfo_res = $specialFieldInfoService->QueryAllSpecialFieldInfo();

		include '../ClassInfo/classInfoManage.php';
	} else if($action == "frontQuery") {
		//查询班级信息信息
		require_once '../service/ClassInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$classNumber = !empty($_POST['classNumber']) ? $_POST['classNumber'] : "";
		$className = !empty($_POST['className']) ? $_POST['className'] : "";
		$classSpecialFieldNumber = !empty($_POST['classSpecialFieldNumber']) ? $_POST['classSpecialFieldNumber'] : "";
		$classBirthDate = !empty($_POST['classBirthDate']) ? $_POST['classBirthDate'] : "";
		//创建ClassInfoService实例
		$classInfoService = new ClassInfoService();

		//创建一个FenyePage对象实例
		$fenyePage = new FenyePage();
		//给fenyePage指定必须的参数
		$fenyePage->pageNow = 1;
		$fenyePage->pageSize = 5;
		$fenyePage->gotoUrl = "ClassInfoAction.php";

		//在此我们需要根据用户的点击来修改pageNow的值，不要判断是否有这个pageNow发送
		if(!empty($_REQUEST['pageNow'])){
			$fenyePage->pageNow=$_REQUEST['pageNow'];
		}

		//调用getFenyePage，该方法可以把fenyePage完成
		$classInfoService->getFenyePage($fenyePage,$classNumber,$className,$classSpecialFieldNumber,$classBirthDate);
		require_once '../service/SpecialFieldInfoService.class.php';
		$specialFieldInfoService = new SpecialFieldInfoService();
		$specialFieldInfo_res = $specialFieldInfoService->QueryAllSpecialFieldInfo();

		include '../ClassInfo/classInfoFrontQuery.php';
	} else if($action == "update") {
		//说明用户希望执行更新班级信息信息
		$array_classInfo = $_POST["classInfo"];
		$classInfo = $classInfoService->GetClassInfo($array_classInfo['classNumber']);
		$classInfo->setClassNumber($array_classInfo['classNumber']);
		$classInfo->setClassName($array_classInfo['className']);
		$classInfo->setClassSpecialFieldNumber($array_classInfo['classSpecialFieldNumber']);
		$classInfo->setClassBirthDate($array_classInfo['classBirthDate']);
		$classInfo->setClassTeacherCharge($array_classInfo['classTeacherCharge']);
		$classInfo->setClassTelephone($array_classInfo['classTelephone']);
		$classInfo->setClassMemo($array_classInfo['classMemo']);
		//完成修改->数据库
		$res = $classInfoService->UpdateClassInfo($classInfo);
		if($res != 0) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "del") {
		//这时我们知道要删除班级信息信息
		$classNumber = $_GET['classNumber'];
		if($classInfoService->DeleteClassInfo($classNumber) == 1) {
			//成功
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	}
}
?>
