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

    include 'include/database.php';

    $connection = connect($database);
    
    $canView = canViewTables($connection, $_SESSION['login']);
    
    if ($canView) {
        $systems = getOfflineSystems($connection);
    } else {
        $systems = null;
    }
    
    $connection = null;

    if ($canView) {
		$offline = '
            <table id="offlineRoomList" class="center">
                <tr>
                    <th>Campus</th>
                    <th>Building</th>
                    <th>Room</th>
                </tr>
        ';

        foreach ($systems as $system) {
            $offline .= "
                <tr>
                    <td>{$system['campus']}</td>
                    <td>{$system['building']}</td>
                    <td>{$system['room']}</td>
                </tr>
            ";        
        }
        
        $offline .= '
            </table>
        ';
        
        echo $offline;
    } else {
        echo '<strong class="warning">You do not have permission to see this yet! Please email the administrator of this system for assistance...</strong>';
    }
?>