#!/usr/bin/runhugs +l \begin{code} import IO import Xhtml1 import SWlib import Codec.Binary.UTF8.String (encodeString) import CGI (cgiVars) main = withEucKrEnv $ do cgivars <-cgiVars let book = cgivars$$"book" let answer = cgivars$$"answer" let ans = cgivars$$"ans" let words' = read$decodeDQ$cgivars$$"words" :: [String] let words = (if answer==ans then id else (++[answer])) words' wctnt <- filecontent $ book ++"/"++ (if words==[] then ".empty" else head words) putStr $ "Content-type: text/html\n\n" ++ html book wctnt words (answer,ans) html book wctnt words (answer,ans) = xhtml1Doc Transitional "UTF-8" << thehtml << ( thehead ( thetitle << "Smart Word" +++ meta "text/html charset='UTF-8'"! ["http-equiv"-="Content-type"] ) +++ thebody!["onload"-="onload()"] << (lastpage +++ hr +++ thispage) ) where lastpage = if (answer=="" && ans=="") then ""+++"" else p << ( (if answer==ans then strong("Correct "++encodeString "맞았소 ! ") else strong("Wrong "++encodeString "틀렸소 ! ") ) +++ "See the answer of the previous question "++encodeString "지난 문제의 정답 페이지 보기 : " +++ answerlink book answer ) thispage = ( script "text/javascript" << ( CDATA $ "\n" ) +++ if (words == []) then form "index.cgi" !["method"-="post","name"-="f"] << p << -- then form "index.lhs" !["method"-="post","name"-="f"] << p << input!["type"-="submit","name"-="ans","value"-="End"] else ( form "sw.cgi" !["method"-="post","name"-="f"] << p << -- ( form "sw.lhs" !["method"-="post","name"-="f"] << p << (input!["type"-="hidden","name"-="book","value"-=book] +++ input!["type"-="hidden","name"-="answer", "value"-=head words] +++ input!["type"-="hidden","name"-="words", "value"-=(encodeDQ$show$tail$words)] +++ input!["type"-="text","name"-="ans"] +++ input!["type"-="submit","name"-="s", "value"-="Enter"] ) +++ CDATA wctnt ) ) answerlink book answer = a!["href"-=uri,"target"-="new"] <