<?php
// header('Content-Type: application/json');

include "send_error_code.php";

$active_stage_list = $_POST['active_stage'];
$cnt = count($active_stage_list);

include "./connect_db.php";

$query = "UPDATE afterschool_activated_stage SET Activated = 0";
$result = $db_conn->query($query);

for($i = 0; $i < $cnt; $i++) {
	$array_item = $active_stage_list[$i];

	$query = "UPDATE afterschool_activated_stage SET Activated = 1 WHERE StageName = ?";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param('s', $array_item);
	$stmt->execute();

	if($stmt->affected_rows > 0) {
	    echo($array_item." : activated<br/>");
	} else {
	    echo $array_item." : db error<br/>";
	}
}

?>