<%args>
$age => 0
$color => ""
</%args>
<HTML>
   <HEAD><TITLE>Test Page</TITLE></HEAD>
   <BODY>
      <P> This is a sample page. Incoming args: color = <% $color %>, age = <% $age %>
% if($manager->can($currentUser, "edit", $preferences)) {
      <FORM ACTION="page.html" METHOD=POST>
         <TABLE>
            <TR>
               <TD>Name:</TD><TD><% $currentUser->getUsername %></TD>
            </TR><TR>
               <TD>Favorite color:</TD>
               <TD>
                  <SELECT NAME="color">
                     <% colorList($preferences) %>
                  </SELECT>
               </TD>
            </TR><TR>
               <TD>Age:</TD>
               <TD>
                  <INPUT TYPE=TEXT NAME="age" 
                         VALUE="<% $preferences->{"age"} %>">
               </TD>
            </TR>
         </TABLE>
	 <P><INPUT TYPE=Submit>
      </FORM>
% } else {
         <TABLE>
            <TR>
               <TD>Name:</TD><TD><% $currentUser %></TD>
            </TR><TR>
               <TD>Favorite color:</TD>
               <TD><% $preferences->{"favoriteColor"} %></TD>
            </TR><TR>
               <TD>Age:</TD>
               <TD><% $preferences->{"age"} %></TD>
            </TR>
         </TABLE>
% }
   <P><B><A HREF="logout.html">LOGOUT</A></B></P>
   </BODY>
</HTML>

<%init>
my $currentUser = Apache2::SiteControl::AccessController::getCurrentUser($r);
my $manager = Apache2::SiteControl::AccessController::getPermissionManager($r);

# This would be where you would access your back-end data store to get
# data...we will simulate this will literals and submitted data:
my $preferences = { favoriteColor => 'Red', age => 20 };
$preferences->{favoriteColor} = $color if($color ne "");
$preferences->{age} = $age if($age != 0);
</%init>

<%once>
sub colorList($)
{
   my $prefs = shift;
   my $result = "";

   for my $color ("Red", "Green", "Blue", "Purple", "Pink")
   {
      if($color eq $prefs->{favoriteColor}) {
         $result .= "<OPTION VALUE=\"$color\" SELECTED>$color\n";
      } else {
         $result .= "<OPTION VALUE=\"$color\">$color\n";
      }
   }
   return $result;
}
</%once>
