<?php
require_once '../phpbean/SpecialFieldInfo.class.php';
require_once '../service/SpecialFieldInfoService.class.php';

//创建了SpecialFieldInfoService实例
$specialFieldInfoService = new SpecialFieldInfoService();

//根据action参数决定用户要执行什么样的操作
if(!empty($_REQUEST['action'])) {
	//接收action值
	$action = $_REQUEST['action'];
	if($action == "add") {
		//说明用户希望执行添加专业信息信息
		$specialFieldInfo = new SpecialFieldInfo();
		$array_specialFieldInfo = $_POST["specialFieldInfo"];
		$specialFieldInfo->setSpecialFieldNumber($array_specialFieldInfo['specialFieldNumber']);
		$specialFieldInfo->setSpecialFieldName($array_specialFieldInfo['specialFieldName']);
		$specialFieldInfo->setSpecialCollegeNumber($array_specialFieldInfo['specialCollegeNumber']);
		$specialFieldInfo->setSpecialBirthDate($array_specialFieldInfo['specialBirthDate']);
		$specialFieldInfo->setSpecialMan($array_specialFieldInfo['specialMan']);
		$specialFieldInfo->setSpecialTelephone($array_specialFieldInfo['specialTelephone']);
		$specialFieldInfo->setSpecialMemo($array_specialFieldInfo['specialMemo']);
		//完成添加->数据库
		$res = $specialFieldInfoService->AddSpecialFieldInfo($specialFieldInfo);
		if($res==1) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "query") {
		//查询专业信息信息
		require_once '../service/SpecialFieldInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$specialFieldNumber = !empty($_POST['specialFieldNumber']) ? $_POST['specialFieldNumber'] : "";
		$specialFieldName = !empty($_POST['specialFieldName']) ? $_POST['specialFieldName'] : "";
		$specialCollegeNumber = !empty($_POST['specialCollegeNumber']) ? $_POST['specialCollegeNumber'] : "";
		$specialBirthDate = !empty($_POST['specialBirthDate']) ? $_POST['specialBirthDate'] : "";
		//创建SpecialFieldInfoService实例
		$specialFieldInfoService = new SpecialFieldInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$specialFieldInfoService->getFenyePage($fenyePage,$specialFieldNumber,$specialFieldName,$specialCollegeNumber,$specialBirthDate);
		require_once '../service/CollegeInfoService.class.php';
		$collegeInfoService = new CollegeInfoService();
		$collegeInfo_res = $collegeInfoService->QueryAllCollegeInfo();

		include '../SpecialFieldInfo/specialFieldInfoManage.php';
	} else if($action == "frontQuery") {
		//查询专业信息信息
		require_once '../service/SpecialFieldInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		$specialFieldNumber = !empty($_POST['specialFieldNumber']) ? $_POST['specialFieldNumber'] : "";
		$specialFieldName = !empty($_POST['specialFieldName']) ? $_POST['specialFieldName'] : "";
		$specialCollegeNumber = !empty($_POST['specialCollegeNumber']) ? $_POST['specialCollegeNumber'] : "";
		$specialBirthDate = !empty($_POST['specialBirthDate']) ? $_POST['specialBirthDate'] : "";
		//创建SpecialFieldInfoService实例
		$specialFieldInfoService = new SpecialFieldInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$specialFieldInfoService->getFenyePage($fenyePage,$specialFieldNumber,$specialFieldName,$specialCollegeNumber,$specialBirthDate);
		require_once '../service/CollegeInfoService.class.php';
		$collegeInfoService = new CollegeInfoService();
		$collegeInfo_res = $collegeInfoService->QueryAllCollegeInfo();

		include '../SpecialFieldInfo/specialFieldInfoFrontQuery.php';
	} else if($action == "update") {
		//说明用户希望执行更新专业信息信息
		$array_specialFieldInfo = $_POST["specialFieldInfo"];
		$specialFieldInfo = $specialFieldInfoService->GetSpecialFieldInfo($array_specialFieldInfo['specialFieldNumber']);
		$specialFieldInfo->setSpecialFieldNumber($array_specialFieldInfo['specialFieldNumber']);
		$specialFieldInfo->setSpecialFieldName($array_specialFieldInfo['specialFieldName']);
		$specialFieldInfo->setSpecialCollegeNumber($array_specialFieldInfo['specialCollegeNumber']);
		$specialFieldInfo->setSpecialBirthDate($array_specialFieldInfo['specialBirthDate']);
		$specialFieldInfo->setSpecialMan($array_specialFieldInfo['specialMan']);
		$specialFieldInfo->setSpecialTelephone($array_specialFieldInfo['specialTelephone']);
		$specialFieldInfo->setSpecialMemo($array_specialFieldInfo['specialMemo']);
		//完成修改->数据库
		$res = $specialFieldInfoService->UpdateSpecialFieldInfo($specialFieldInfo);
		if($res != 0) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "del") {
		//这时我们知道要删除专业信息信息
		$specialFieldNumber = $_GET['specialFieldNumber'];
		if($specialFieldInfoService->DeleteSpecialFieldInfo($specialFieldNumber) == 1) {
			//成功
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	}
}
?>
