<?php
    session_start();
	if ( empty($_SESSION['login']) ) {
        header( 'Location: login.php' );
        die;
	}

    include 'include/database.php';

    $connection = connect($database);

    $canAdmin = canAdministrate($connection, $_SESSION['login']);
    
    if ($canAdmin) {
        $room_id = getRoomId($connection, $_POST['campus'], $_POST['building'], $_POST['room']);
        return insertUpdateButton($connection, $room_id, $_POST['group_name'], $_POST['button_name'], $_POST['command']);
    } else {
        header( 'Location: /' );
        $connection = null;
        die;
    }
?>