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

    include 'include/database.php';

    $connection = connect($database);

    $canEdit = canEditValues($connection, $_SESSION['login']);
    
    if ($canEdit) {
        $room_id = getRoomId($connection, $_POST['campus'], $_POST['building'], $_POST['room']);
        $is_edited = editRoom($connection, $room_id, $_POST['newName']);
        if (!$is_edited) {
            http_response_code(409); // i.e. 409 Conflict
        }
    }

    $connection = null;
?>