<?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, $_GET['campus'], $_GET['building'], $_GET['room']);
        $executor = getRoomExecutor($connection, $room_id);
        $procs = getCommandProcessors($connection);
        
        $connection = null;
        
        $proc_options = '';
    
        foreach ($procs as $proc) {
            if ($proc['id'] === $executor['id']) {
                $proc_options .= "
                    <option value=\"{$proc['name']}\" selected>{$proc['name']}</option>
                ";
            } else {
                $proc_options .= "
                    <option value=\"{$proc['name']}\">{$proc['name']}</option>
                ";
            }
        }
    
        echo $proc_options;
    }
?>