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

	$username = mysqli_real_escape_string($conn,$_GET["username"]);
	$password = hash('sha256', mysqli_real_escape_string($conn,$_GET["password"]), false);
	$email = mysqli_real_escape_string($conn,$_GET["email"]);
	$accountType = $_GET["role_id"]; // 0 = Participant (Base AccountType)
	$school_id = $_GET["school_id"]; // 0 = Unallocated (particpants don't belong to a school)
    $class_id = $_GET["class_id"]; // 0 = Unallocated (particpants don't belong to a class)
	$verify_code = 0;
	$completed_demographic = 0;
	$completed_survey = 0;

		// generate 'id'
		$result = $conn->query("SELECT * FROM user_account");
			if($result) {
				$id = 1;
				while ( $row = $result->fetch_assoc() ){
					
					if ($id <= $row['user_id']){  //if 'id' already exist, increment
						$id = $row['user_id'] +1;
					}
				}
			}


		if ($conn->query("INSERT INTO user_account VALUES ('$id', '$username', '$password', '$email', $accountType, '$school_id', '$class_id', NOW(), NOW(), '$verify_code', '$completed_demographic', '$completed_survey', 1)") === TRUE) {
			echo 1;
		}
	
   $conn->close();
?>