module Main where

import Network.CGI
import Data.Maybe
import System.IO

import DB
import Session
import ShowMessages
import FancyHtml

main = runCGI $ handleErrors cgiMain

cgiMain = do
    sessionId <- getInput "sessId"
    validsess <- liftIO $ check_session_id $ fromJust sessionId
    user      <- liftIO $ get_session_user $ fromJust sessionId
    if (validsess)
        then showSentMessages user
        else output $ header ++ errorBox "Incorrect session ID, go away!" ++ footer

showSentMessages user = do
    messages <- liftIO $ db_select $ "SELECT msg_digest, recipient, subject, plaintext, sent_date FROM messages WHERE sender LIKE '" ++ user ++ "'"
    output $ header ++ "<h1>Messages sent by " ++ user ++ "</h1><table border=1><tr><th>Digest</th><th>Recipient</th><th>Subject</th><th>Message</th><th>Sent date</th></tr>" ++ (showMessagesWithLink messages) ++ "</table>" ++ (quote "If the designers of X-Windows built cars, there would be no fewer than five steering wheels hidden about the cockpit, none of which followed the same principles &#8212; but you'd be able to shift gears with your car stereo. Useful feature, that." "http://www.schnada.de/quotes/contempt.html" "Marcus J. Ranum") ++ footer
