<?php
// MPickering: modified; this will be enclosed within an ul

if (empty($FORMNAME))
    $FORMNAME = 'signin';
else
    $NOFORM = true;
?>
<?php if (empty($NOFORM)) { ?>
 <li>
  <form method="post" action="<?php echo $request->getPostURL()?>" accept-charset="UTF-8" name="<?php echo $FORMNAME?>">
  <?php echo HiddenInputs($request->getArgs(), false, array('auth')) ?>
<?php } ?>
<?php
if ($user->isAuthenticated()) {
    $SignOutB = $WikiTheme->makeButton(_("Sign Out"), "javascript:SignOut();", 'wikiaction');
?>
<span>
  <?php echo fmt("Authenticated as %s", WikiLink($user->getAuthenticatedId(), 'auto')) ?>
  <?php echo $SEP?>
</span>
  <script type="text/javascript"><!--
    document.write('<br /><input type="hidden" name="auth[logout]" value="0" />');
    function SignOut() {
      var form = document.forms["<?php echo $FORMNAME?>"];
      form.elements["auth[logout]"].value = 1;
      form.submit();
    }
    document.write('<?php echo $SignOutB?>'); // -->
  </script>
  <noscript>
    <?php echo Button("submit:auth[logout]", _("Sign Out"), 'wikiaction') ?>
  </noscript>
<?php } else {
    $SignInInput = HTML::input(array('type' => 'text',
				     'name' => "auth[userid]",
				     'size' => 12,
				     'maxlength' => 256,
				     'onchange' => "SignIn(this.form,false);"));
    $SignInInput->addTooltip(_("Enter your UserId to sign in"));
    $userid = $user->getId();
    if ($user->isSignedIn())
      echo sprintf(_("You are signed but not authenticated as %s. "),
		   asXml(HTML::a(array(
				       'href'=>'#',
				       'title' => sprintf(_("Click to authenticate as %s"),$userid),
				       'onclick'=>'SignIn(document.forms["'.$FORMNAME.'"],"'.$userid.'");'),
				 $userid)));
?>
  <script type="text/javascript"> <!--
     function SignIn(form,userid) {
      <?php if (defined('EDITING_POLICY') and $request->_dbi->isWikiPage(EDITING_POLICY)) { ?>
      if (window.focus) {
        window.open('<?php echo WikiUrl(EDITING_POLICY) ?>',<!-- url -->
                    'PleaseReadThisFirst',<!-- window name -->
                    'width=600,height=430,scrollbars=yes,resizable=yes,toolbar=yes');
      }
      <?php } ?>
      if (userid) {
        form.elements["auth[userid]"].value = userid;
      }
      form.submit();
    }
    //-->
  </script>
  <?php echo Button("submit:auth[login]", _("Sign in as:"), 'wikiaction')?>
  <?php echo $SignInInput ?>
<?php /* // sf.net bug #950841 "Sign In:" button appears twice
  <noscript>
    <?php echo Button("submit:auth[login]", _("Sign in as:"), 'wikiaction')?>
  </noscript>
*/ ?>
<?php } ?>
<?php if (empty($NOFORM)) { ?>
  </form>
 </li>
<?php } ?>
