<?php

    // Make sure the user is logged in:
    session_name('chat_hw10');
    session_start();
    if (empty($_SESSION['username']))
    {
        header("Location: login.php");
        exit;
    }

    // To show the chats, we need to load them from the database.
    include("connect.php");

    $get_messages_query = $db->prepare("
        SELECT * FROM `messages`
        ORDER BY `messageid` ASC
    ");
    $get_messages_query->execute();

    $messages = $get_messages_query->fetchAll();
    $smarty->assign('messages', $messages);
    $smarty->display('chat.tpl');

?>
