<?php session_start(); 

require "common.php";
if (isset($_SESSION['role'])){
	$role =$_SESSION['role'];
}
if (isset($_GET['lang'])){
	$_SESSION['lang'] = $_GET['lang'];
}
if (isset($_SESSION['lang'])){
	if ($_SESSION['lang'] == "chi"){
		require "language/chi.php";
	} else {
		require "language/eng.php";
	}
$lang = $_SESSION['lang'];
}

if(isset($_SESSION['UID']) != null){ 
	$UID = $_SESSION["UID"];  
		if (isset($_SESSION['STAFFCODE'])) {
		$staffcode = $_SESSION['STAFFCODE'];
		if ($_SESSION['lang'] == "chi") {
			$name = $_SESSION['CH_NAME'];
		} else {
			$name = $_SESSION['EN_NAME'];
		}
	} else {
		$stuid = $_SESSION['STUID'];
		$classcode = $_SESSION['CLASSCODE'];
		$classno = $_SESSION['CLASSNO'];
		if ($_SESSION['lang'] == "chi") {
			$name = $_SESSION['CH_NAME'];
		} else {
			$name = $_SESSION['EN_NAME'];
		}
		
	}
	foreach ($_POST as $key => $value) 	{ 
			if ($key !== "role") {
				$$key = $value;    //2個$$代表轉為VARIABLE
			}
	}
	foreach ($_GET as $key => $value) 	{ 
			if ($key !== "role") {
				$$key = $value;    //2個$$代表轉為VARIABLE
			}
	}


//設定學年
		$findmax = mysqli_query($splink,"Select MAX(SCHYEAR) FROM SCHYEAR");
		while ($getmax = mysqli_fetch_row($findmax)){
			$todayschyr = $getmax[0];
		}
		if (!isset($targetschoolyear)){
			$targetschoolyear = $todayschyr;
		}

//完成設定學年
//學年選擇表		
			$sql=mysqli_query($splink,"Select SCHYEAR from SCHYEAR ORDER BY SCHYEAR DESC");
			$yearlist = "";
			while ($row = mysqli_fetch_row($sql)){
				if (isset($targetschoolyear)){
					if ($targetschoolyear == $row[0]) {
						$selected = "selected";
					} else {
						$selected = "";
					}
				} else {
					$selected = "";
				}
				$pp = $row[0]+1;
				$yearlist .="<option value=\"".$row[0]."\" ".$selected.">".$row[0]."-".substr($pp,2)."</option>";
			//	$yearlist .="<option value=\"".$row[0]."\" ".$selected.">".$row[0]."</option>";
			}
//完成學年選擇表

	require "templates/header.php"; 







	require "templates/footer.php";
	mysqli_close($splink);
} else {
	require "language/eng.php";
	echo $txtnoright;
	echo '<meta charset="utf-8"';
	echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
}
?>