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

<perl><![CDATA[

=head1 NAME

macro/admin - user access utilities for PApp

=head1 SYNOPSIS

 use PApp;
 <import src="macro/admin"/>

=head1 DESCRIPTION

See L<PApp::UserObs> for most of the functions that formerly were defined
here.

=head2 EXPORTED FUNCTIONS

=over 4

=cut

use PApp::UserObs ();

my $surl_login_cb = create_callback {
   my ($user, $pass) = ($P{papp_resu}, $P{papp_ssap});
   $PApp::arguments{papp_login_failed} = !PApp::UserObs::verify_login $user, $pass if $user;
} name => "papp_login";

]]></perl>

<macro name="loginbox*"><phtml><![CDATA[<:

=item loginbox

Display a login box unless the user has authenticitated herself.

=cut

:>
#if $PApp::arguments{papp_login_failed}
   <?errbox __"Login failed", __"no such user or wrong password":>
#endif
   <p />
   <?cform SURL_EXEC($surl_login_cb):>
      <table cellpadding="0" cellspacing="0" border="0">
         <tr><td></td><td>
            __"You may log-in now!"
         </td></tr><tr><td>
               __"Username:"
            </td><td>
               <?textfield {size => 12, maxlength => 32 }, "papp_resu":>
         </td></tr><tr><td>
               __"Password:"
            </td><td>
               <?password_field {size => 12, maxlength => 32 }, "papp_ssap":>
         </td></tr><tr><td></td><td>
            <?submit "papp_nigol" => __"Log In":>
         </td></tr>
      </table>
   <?endform:>
   <p />
]]></phtml></macro>

<macro name="adminbox*(;&amp;)"><phtml><![CDATA[<:

=pod adminbox(;&amp;)

Display a very visible box with some information interesting for admins,
developers, translators, editors, authors... The optional block will
be executed so you can add page-specific  info.

=cut

:>
   <table width="100%" bgcolor="#ffffa0" cellpadding="20" cellspacing="0" border="0">
      <tr><td><font color="#000000">
         <h1>Admin-Info</h1>

         __"You are currently known to me as user #"<b><?$PApp::userid:></b><br />
#if PApp::UserObs::authen_p
         __"Current access rights include" <:
            use bytes;
            for (1 .. 8*length $state{papp_access}) {
               if (vec $state{papp_access}, $_, 1) {
                  no bytes;
                  echo "$_ (", (sql_fetch $PApp::Config::DBH, "select name from grp where id = ?", $_), "), ";
               }
            }
         :><br />
#else
         __"(You are not currently logged in)"<br />
#endif

         <?sprintf __"This page has been reloaded <b>%d</b> times.", PApp::reload_p:><br />

         __"<i>Possible(!)</i> URI (for referencing) of this page:" <?alink ((reference_url 1)x2):><br />
         __"Never, <i>EVER</i> publish a url with the hex-hash key in it(!)"<p />
         <?slink __"Reload page and drop all priviledges", &PApp::UserObs::SURL_USER_LOGOUT:>

         <:@_ and &{$_[0]}:>
      </font></td></tr>
   </table>
]]></phtml></macro>

<macro name="check_login*"><phtml><![CDATA[<:

=item check_login

- if the user is not logged in, show a loginbox
- if the user has logged in, display some info about him

*DEPRECATED*

=cut

:>
#if PApp::UserObs::authen_p
   <:adminbox:>
#else
   <:loginbox:>
#endif
]]></phtml></macro>

<macro name="force_login*($)" args="$msg"><phtml><![CDATA[<:
abort_with {
   PApp::UserObs::user_logout;
   content_type "text/html";
   :><html><head><title><?$msg:></title></head><:
   :><body text="black" link="#1010C0" vlink="#101080" alink="red" bgcolor="white"><:
   :><h1><?$msg:></h1><:
   loginbox;
   :></body></html><:
}
:>]]></phtml></macro>

<perl><![CDATA[

=back

=head1 SEE ALSO

L<PApp>

=head1 AUTHOR

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

=cut

]]></perl>

</domain>
</package>

