<?php
require_once '../phpbean/CollegeInfo.class.php';
require_once '../service/CollegeInfoService.class.php';

//创建了CollegeInfoService实例
$collegeInfoService = new CollegeInfoService();

//根据action参数决定用户要执行什么样的操作
if(!empty($_REQUEST['action'])) {
	//接收action值
	$action = $_REQUEST['action'];
	if($action == "add") {
		//说明用户希望执行添加学院信息信息
		$collegeInfo = new CollegeInfo();
		$array_collegeInfo = $_POST["collegeInfo"];
		$collegeInfo->setCollegeNumber($array_collegeInfo['collegeNumber']);
		$collegeInfo->setCollegeName($array_collegeInfo['collegeName']);
		$collegeInfo->setCollegeBirthDate($array_collegeInfo['collegeBirthDate']);
		$collegeInfo->setCollegeMan($array_collegeInfo['collegeMan']);
		$collegeInfo->setCollegeTelephone($array_collegeInfo['collegeTelephone']);
		$collegeInfo->setCollegeMemo($array_collegeInfo['collegeMemo']);
		//完成添加->数据库
		$res = $collegeInfoService->AddCollegeInfo($collegeInfo);
		if($res==1) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "query") {
		//查询学院信息信息
		require_once '../service/CollegeInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		//创建CollegeInfoService实例
		$collegeInfoService = new CollegeInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$collegeInfoService->getFenyePage($fenyePage);
		include '../CollegeInfo/collegeInfoManage.php';
	} else if($action == "frontQuery") {
		//查询学院信息信息
		require_once '../service/CollegeInfoService.class.php';
		require_once '../service/FenyePage.class.php';
		//获取查询参数
		//创建CollegeInfoService实例
		$collegeInfoService = new CollegeInfoService();

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

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

		//调用getFenyePage，该方法可以把fenyePage完成
		$collegeInfoService->getFenyePage($fenyePage);
		include '../CollegeInfo/collegeInfoFrontQuery.php';
	} else if($action == "update") {
		//说明用户希望执行更新学院信息信息
		$array_collegeInfo = $_POST["collegeInfo"];
		$collegeInfo = $collegeInfoService->GetCollegeInfo($array_collegeInfo['collegeNumber']);
		$collegeInfo->setCollegeNumber($array_collegeInfo['collegeNumber']);
		$collegeInfo->setCollegeName($array_collegeInfo['collegeName']);
		$collegeInfo->setCollegeBirthDate($array_collegeInfo['collegeBirthDate']);
		$collegeInfo->setCollegeMan($array_collegeInfo['collegeMan']);
		$collegeInfo->setCollegeTelephone($array_collegeInfo['collegeTelephone']);
		$collegeInfo->setCollegeMemo($array_collegeInfo['collegeMemo']);
		//完成修改->数据库
		$res = $collegeInfoService->UpdateCollegeInfo($collegeInfo);
		if($res != 0) {
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	} else if($action == "del") {
		//这时我们知道要删除学院信息信息
		$collegeNumber = $_GET['collegeNumber'];
		if($collegeInfoService->DeleteCollegeInfo($collegeNumber) == 1) {
			//成功
			header("Location: /ok.php");
			exit();
		} else {
			//失败
			header("Location: /error.php");
			exit();
		}
	}
}
?>
