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

	session_start();


	$username = $_SESSION['user'];
	$username_new = $_GET['username'];
	$sid = $_GET['sid'];
	// echo "no code is found";

	$result = $conn->query("SELECT * FROM user_account WHERE accountType < 2");
		
		if($result) {
			
			$existed = false;

			while ( $row = $result->fetch_assoc() ){
				if ( $row['username'] == $username_new  ){
					$existed = true;
				}
			}

			if ($existed == true){
				if ($conn->query("UPDATE user_account SET accountType = 2, school_id = '".$sid."', class_id = 0 WHERE username='".$username_new."'") === TRUE){
					echo 1;
		        }
		        else {
		            echo 0;
		        }
			}
			else
				echo 0;
		}
	   
	$conn->close();
?>