<?php
	include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");


	$code=$_GET['code'];
	// echo "no code is found";
	$foundCode = false;

	$result_1 = $conn->query("SELECT * FROM school_class");
		
		if($result_1) {
			while ( $row = $result_1->fetch_assoc() ){
				// echo 'no code is found';
				if ($row['specific_classCode'] == $code){
					// echo "<span>class: <b>".$row['class_name']."</b></span>";
					// echo "<br>";
					// echo "<span>account type: <b>Student</b></span>";
					$result_s = $conn->query("SELECT * FROM school WHERE school_id=".$row['school_id']);
					
					if ($result_s){
						while ( $row_s = $result_s->fetch_assoc() ){
							
							echo '1,'.$row['school_id'].','.$row_s['school_name'].',class,'.$row['class_name'].',Student';

							$foundCode = true;
							exit();
						}
					}
				}
			}

			// 0: accType-id | 1: school-id | 2: school-name | 3: label | 4: class-name | 5: accType
		}

	$result_2 = $conn->query("SELECT * FROM school");
		
		if($result_2) {
			while ( $row_2 = $result_2->fetch_assoc() ){
				
				if ($row_2['specific_teacherCode'] == $code){
					// echo "<span>school: <b>".$row_2['school_name']."</b></span>";
					// echo "<br>";
					// echo "<span>account type: <b>Teacher</b></span>";
					echo '2,'.$row_2['school_id'].','.$row_2['school_name'].',school,'.$row_2['school_name'].',Teacher';
					$foundCode = true;
					exit();
				}
				else if ($row_2['specific_sAdminCode'] == $code){
					// echo "<span>school: <b>".$row_2['school_name']."</b></span>";
					// echo "<br>";
					// echo "<span>account type: <b>School-Admin</b></span>";
					echo '3,'.$row_2['school_id'].','.$row_2['school_name'].',school,'.$row_2['school_name'].',School-Admin';
					$foundCode = true;
					exit();
				}				
			}

			// 0: accType-id | 1: school-id | 2: school-name | 3: label | 4: class-name | 5: accType
		}

	if ($foundCode == false){
		// echo "<span>the code is invalid</span>";
		echo '0,,,,,';
	}



	// $result = $conn->query("SELECT * FROM school_class, school");
		
	// 	if($result) {
			
	// 		$foundCode = false;
	// 		while ( $row = $result->fetch_assoc() ){
				
	// 			// echo 'no code is found';
	// 			if ($row['specific_classCode'] == $code){
	// 				// echo "<span>class: <b>".$row['class_name']."</b></span>";
	// 				// echo "<br>";
	// 				// echo "<span>account type: <b>Student</b></span>";
	// 				echo '1,'.$row['school_id'].','.$row['school_name'].',class,'.$row['class_name'].',Student';
	// 				$foundCode = true;
	// 				exit();
	// 			}

	// 			if ($row['specific_teacherCode'] == $code){
	// 				// echo "<span>school: <b>".$row['school_name']."</b></span>";
	// 				// echo "<br>";
	// 				// echo "<span>account type: <b>Teacher</b></span>";
	// 				echo '2,'.$row['school_id'].','.$row['school_name'].',school,'.$row['school_name'].',Teacher';
	// 				$foundCode = true;
	// 				exit();
	// 			}
	// 			else if ($row['specific_sAdminCode'] == $code){
	// 				// echo "<span>school: <b>".$row['school_name']."</b></span>";
	// 				// echo "<br>";
	// 				// echo "<span>account type: <b>School-Admin</b></span>";
	// 				echo '3,'.$row['school_id'].','.$row['school_name'].',school,'.$row['school_name'].',School-Admin';
	// 				$foundCode = true;
	// 				exit();
	// 			}				
	// 		}

	// 		if ($foundCode == false){
	// 			// echo "<span>the code is invalid</span>";
	// 			echo '0,,,,,';
	// 		}

	// 		// 0: accType-id | 1: school-id | 2: school-name | 3: label | 4: class-name | 5: accType
	// 	}

	$conn->close();
?>