<package name="util">
<domain name="papp" lang="en">

<perl><![CDATA[
=head1 NAME

macro/util - some utility functions

=head1 SYNOPSIS

 <import src="macro/util"/>

=head1 DESCRIPTION

*sigh* :(

=head1 FUNCTIONS

=over 4

=item plain_header [title]

Create a plain and ugly html header (with an optional title).

=item plain_footer

Create a plain and ugly html footer.

=item access_page $access, $title, \&body

Create a simple access-protected page. C<$access> is the required access
level (L<macro/editform>), C<$title> is the page title. The C<body>
argument must be a function reference. If the user has the required access
right a plain page is created (using the functions above) and the body
function is called. Otherwise the user is informed of his missing rights
and gets the opportunity to log-in.

Use it like this:

   <phtml><![CDATA[
   <:access_page "app_access", "Main Page", sub {:>
      <h1>Main Page</h1>
      You are logged in now ;)
   <:}:>
   ]]>]]&lt;<![CDATA[

=back

=cut

]]></perl>

<import pm="PApp::UserObs">access_p</import>
<import src="macro/admin"/>

<macro name="plain_header*(;$)" args="$head"><phtml><![CDATA[
#if !ref $head
<: $head = { title => $head } :>
#endif
<html>
 <head>
 <title><?$head->{title}:></title>
 <?$head->{head}:>
 </head>
 <body link="#a000000" alink="#a00000" vlink="#a00000" text="#000000" bgcolor="#ffffb4">
]]></phtml></macro>

<macro name="plain_footer*"><phtml><![CDATA[
 </body>
</html>
]]></phtml></macro>

<macro name="access_page*($$$)" args="$access $title $body"><phtml><![CDATA[
<:plain_header $title:>
#if !access_p $access
     <:loginbox:>
#endif
#if access_p $access
     <: &$body :>
#else
   __"I fear you do not have the necessary... well... access rights to do anything on this page..."
# if retlink_p
     <p>[returl] <?retlink __"Go Back":>
# endif
# if $request->header_in('Referer')
     <p>[referer] <?alink __"Send me back to wherever I came from", $request->header_in('Referer'):>
# endif
#endif
<:plain_footer:>
]]></phtml></macro>

<perl><![CDATA[
=head1 SEE ALSO

L<PApp>

=head1 AUTHOR

 Marc Lehmann <pcg@goof.com>
 http://www.goof.com/pcg/marc/

=cut

]]></perl>

</domain>
</package>

