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

	$sid = $_GET["sid"];
	// $sOrder = $_GET["sOrder"];

		if ($result = $conn->query("DELETE FROM school_class WHERE class_id='".$sid."'") === TRUE) {

			// $result = $conn->query("UPDATE survey SET order_id='".$sOrder."' WHERE order_id>'".$sOrder."'");

			// delete all assigned class_id from user
			$result = $conn->query("UPDATE user_account SET class_id = 0 WHERE class_id = '".$sid."' ");


			$orderID = $sid;

			$res_reAllocateID = $conn->query("SELECT * FROM school_class WHERE class_id > '$sid' ");
				if($res_reAllocateID) {
					while ( $row = $res_reAllocateID->fetch_assoc() ){
						// $orderID_new = $orderID + 1;
						$result = $conn->query("UPDATE school_class SET class_id = '$orderID' WHERE class_id = ".$row['class_id']." ");
						$orderID++;
					}
				}
		}

   $conn->close();
?>