<?php
	$act=$_REQUEST['act'];

	switch ($act){
        case 'update_sSchool':
            $sid = $_REQUEST['sid'];
            $school = $_REQUEST['school'];
            updateStudentSchool($sid,$school);
            break;
        case 'update_sClass':
            $sid = $_REQUEST['sid'];
            $class = $_REQUEST['class'];
            updateStudentClass($sid,$class);
            break;
        case 'update_sStatus':
            $sid = $_REQUEST['sid'];
            $status = $_REQUEST['status'];
            updateStudentStatus($sid,$status);
            break;
    }

    function updateStudentStatus($sid,$status){
        //we will get the id which will be 0 in case of not-active
        //It will be 1 in case account becomes active
        include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");
        $result = $conn->query("UPDATE user_account SET active = '$status' WHERE user_id = '$sid'");
        $conn->close();
    }
    
    function updateStudentClass($sid,$classid){
        //In this case we will get the class of the student
        //But also we update the school id of the user_account
        include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");
        $schoolID = 0;
        $result = $conn->query("SELECT * FROM school_class WHERE class_id = '$classid'");
        if($result){
            while($row = $result->fetch_assoc()){
                $schoolID = $row['school_id'];
            }
        }
        //Now that we have got the school_id for that class
        $result = $conn->query("UPDATE user_account SET school_id = '$schoolID', class_id = '$classid' WHERE user_id = '$sid'");
        $conn->close();
    }

    function updateStudentSchool($sid,$schoolid){
        include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");
        $result = $conn->query("UPDATE user_account SET school_id = '$schoolid', class_id = '0' WHERE user_id = '$sid'");
        $conn->close();
    }

?>