<?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']);
        $buttons = getCommandButtons($connection, $room_id);
        
        $button_table = '
            <table class="center">
                <tr>
                    <th>Button Group</th>
                    <th>Button Caption</th>
                    <th>Associated Command</th>
                    <th>Options</th>
				</tr>
        ';
        
        foreach ($buttons as $button) {
            $button_table .= "
                <tr title=\"{$button['id']}\">
                    <td>{$button['group_name']}</td>
                    <td>{$button['name']}</td>
                    <td>{$button['command']}</td>
                    <td>
                        <button onclick=\"cmdBtnClick({$button['id']})\">Test</button>
                        <button onclick=\"deleteCmdButton({$button['id']})\">Delete</button>
                    </td>
                </tr>
            ";
        }
        
        $button_table .= '
            </table>
        ';
        
        echo $button_table;
    } else {
        header( 'Location: /' );
        $connection = null;
        die;
    }
    
    $connection = null;
?>