| 1 | <HTML> |
| 2 | <HEAD><TITLE>Test Page</TITLE></HEAD> |
| 3 | <BODY> |
| 4 | <P> This is a sample page. |
| 5 | <p><a href="/sample/site/logout.html">Logout</a></p> |
| 6 | % if($manager->can($currentUser, "edit", $preferences)) { |
| 7 | <FORM ACTION="null" METHOD=POST> |
| 8 | <TABLE> |
| 9 | <TR> |
| 10 | <TD>Name:</TD><TD><% $currentUser %></TD> |
| 11 | </TR><TR> |
| 12 | <TD>Favorite color:</TD> |
| 13 | <TD> |
| 14 | <SELECT NAME="color"> |
| 15 | <% colorList($preferences) %> |
| 16 | </SELECT> |
| 17 | </TD> |
| 18 | </TR><TR> |
| 19 | <TD>Age:</TD> |
| 20 | <TD> |
| 21 | <INPUT TYPE=TEXT NAME="age" |
| 22 | VALUE="<% $preferences->{"age"} %>"> |
| 23 | </TD> |
| 24 | </TR> |
| 25 | </TABLE> |
| 26 | <P><INPUT TYPE=Submit> |
| 27 | </FORM> |
| 28 | % } else { |
| 29 | <TABLE> |
| 30 | <TR> |
| 31 | <TD>Name:</TD><TD><% $currentUser %></TD> |
| 32 | </TR><TR> |
| 33 | <TD>Favorite color:</TD> |
| 34 | <TD><% $preferences->{"favoriteColor"} %></TD> |
| 35 | </TR><TR> |
| 36 | <TD>Age:</TD> |
| 37 | <TD><% $preferences->{"age"} %></TD> |
| 38 | </TR> |
| 39 | </TABLE> |
| 40 | % } |
| 41 | </BODY> |
| 42 | </HTML> |
| 43 | |
| 44 | <%init> |
| 45 | my $currentUser = Apache2::SiteControl->getCurrentUser($r); |
| 46 | my $manager = Apache2::SiteControl->getPermissionManager($r); |
| 47 | |
| 48 | # This would be where you would access your back-end data store to get |
| 49 | # data...we will simulate this will literals: |
| 50 | my $preferences = { favoriteColor => 'Red', age => 20 }; |
| 51 | </%init> |
| 52 | |
| 53 | <%once> |
| 54 | sub colorList($) |
| 55 | { |
| 56 | my $prefs = shift; |
| 57 | my $result = ""; |
| 58 | |
| 59 | for my $color ("Red", "Green", "Blue", "Purple", "Pink") |
| 60 | { |
| 61 | if($color eq $prefs->{"favoriteColor"}) { |
| 62 | $result .= "<OPTION SELECTED>$color\n"; |
| 63 | } else { |
| 64 | $result .= "<OPTION>$color\n"; |
| 65 | } |
| 66 | } |
| 67 | return $result; |
| 68 | } |
| 69 | </%once> |