Bulletin board - Eleven source code

options
{
  app_name       = "Eleven bulletin board";
  package_name   = "board";
  display_header = "no";
}

//------------------------------------------------------------
// Define bulletin board livetable
//------------------------------------------------------------

statesafe livetable
{
  db_table = "eleven_board";

  var creation_time;
  var author;
  var comment;
} bulletinBoard;

bulletinBoard.sort ("creation_time desc");

//------------------------------------------------------------
// Subroutine to post a comment
//------------------------------------------------------------

sub postComment (var unused)
{
  statesafe var author;
  statesafe text comment;

  display
    {
      print ("You are about to post a comment to the Eleven bulletin board.
              HTML commands and blank lines will be ignored. You will get
              a chance to preview your comment before posting.");

      edit ("Your name: ", author);
      edit ("Your comment: ", comment);
    }

  statesafe array r;
  r {'creation_time'} = now ();
  r {'author'} = author;
  r {'comment'} = comment;

  display
    {
      print ("Here is a preview of your comment. To change it, use the
              <b>back</b> button on your web browser. To cancel, browse
              to another web page and ignore this one.");

      print ("Once you click <b>continue</b>, your post will be finalized and
              added to the bulletin board. You will not be able to change it
              after that, so make sure everything is correct!");

      print ("Preview:");

      tableformat
	{
	  rowformat
	    {
	      cell
		{
		  print [class="bulletinBoardAuthor"] ("Posted by " . r{'author'} . " on " . r{'creation_time'} . ":");
		  print [class="bulletinBoardComment"] (r{'comment'});
		}
	    }
	}
    }

  statesafe var status = bulletinBoard.insert (r);
  display
    {
      if (status eq "ok")
	{
	  print ("Your comment was successfully posted to the bulletin board.");
	}
      else
	{
	  print ("Error: ", status);
	}
    }
}

//------------------------------------------------------------
// Main bulletin board display
//------------------------------------------------------------

display no_continue
{
  print [position="header"] ("<b>Eleven bulletin board</b>");
  print [position="header"] ('This lightweight bulletin board application was written in Eleven.
                              <a href="board.html">Click here</a> to view the source code.');

  callbutton ("Post a comment", postComment, 0);

  browse bulletinBoard
    dataformat (r)
    {
      cell
	{
	  print [class="bulletinBoardAuthor"] ("Posted by " . r{'author'} . " on " . r{'creation_time'} . ":");
	  print [class="bulletinBoardComment"] (r{'comment'});
	}
    }
}