<?php // -*-php-*- ?>
<!-- $Id: login.tmpl,v 1.35 2004/11/05 21:03:27 rurban Exp $ -->
<!-- The login form -->
<?php if ($fail_message) { ?>
  <p><strong><?=$fail_message?></strong></p>
  <hr noshade="noshade" />
<?php } ?>
<?php /* br past the logo */ ?>
<br class="clear-floats" />

<?php 
if (DEBUG & _DEBUG_LOGIN) {
  $t = sprintf("  DEBUG: ALLOW_ANON_EDIT = %s, ALLOW_BOGO_LOGIN = %s, ALLOW_USER_PASSWORDS = %s, ENABLE_PAGEPERM = %s, ", 
	       ALLOW_ANON_EDIT ? "true" : "false",
	       ALLOW_BOGO_LOGIN ? "true" : "false",
	       ALLOW_USER_PASSWORDS ? "true" : "false",
               ENABLE_PAGEPERM ? "true" : "false");
  if (ALLOW_USER_PASSWORDS) {
    if ($fail_message) { // add for each method the exact failing reason.
      $t .= "  USER_AUTH_ORDER: ";
      foreach ($GLOBALS['USER_AUTH_ORDER'] as $auth) {
          $t .= " => $auth";
          if ($fail = @$GLOBALS['USER_AUTH_ERROR']["_".strtolower($auth)."passuser"])
              $t .= " ($fail)";
      }
    } else
      $t .= sprintf("  USER_AUTH_ORDER: %s", join(" => ", $GLOBALS['USER_AUTH_ORDER']));
    $t .= sprintf(",  USER_AUTH_POLICY: %s", USER_AUTH_POLICY)
       . sprintf(",  PASSWORD_LENGTH_MINIMUM: %s", PASSWORD_LENGTH_MINIMUM);
  }
  echo asXML(HTML::div(array('class' => 'debug'),$t));
  echo "<br />\n";
}
if (ALLOW_BOGO_LOGIN && $require_level <= WIKIAUTH_BOGO) {
  require_once("lib/BlockParser.php");
  // This iso-8859-1 sample covers French, Spanish, Italian, German, and probably others
  if (check_php_version(4,3))
    $examplechars = htmlentities("ÀñíçéàÖãæôßøü", ENT_QUOTES, $charset);
  elseif (check_php_version(4,0,3))
    $examplechars = htmlentities("ÀñíçéàÖãæôßøü", ENT_QUOTES);
  else
    $examplechars = htmlentities("ÀñíçéàÖãæôßøü");
  // Japanese login requires utf-8 and ALLOW_NONWIKIWORD_LOGINS
  if (($charset == 'utf-8') && defined('ALLOW_NONWIKIWORD_LOGINS') && ALLOW_NONWIKIWORD_LOGINS) {
    //sample Japanese login name in unicode
    $examplechars = $examplechars . "&#22825;&#36947;&#12354;&#12363;&#12397;";
  }
  $t = asXML(TransformText(_("You may sign in using any [WikiWord|AddingPages] as a user id. (Any characters in %s etc. may be used too). The user id will be used as a link in RecentChanges to your home page."), 2.0, true));
  if (substr_count($t,"%s") == 1) {
      $s = @sprintf($t, $examplechars);
      // FIXME: Workaround gettext or sprintf problem
      if (empty($s)) echo $t;
      else echo sprintf($t, $examplechars);
  } else {
      echo $t;
  }
  /* On disabled DbPrefs (PagePrefs only) note the user to create his PersonalPage. */
  // don't understand why I put this in --rurban
  if (!isset($user->_prefs->_select)) {
    echo asXML(TransformText(_("Note: Only if you create your personal HomePage with same the pagename as your user id, you will be able to store your UserPreferences. Otherwise not.")));
  }
  if (empty($pass_required)) ?>
  <p><?= _("New users may use an empty password.") ?></p>
<?php } ?>
<form method="post" action="<?= $request->getPostURL() ?>" accept-charset="<?=CHARSET?>" name="login">
<table cellspacing="4">
<tr>
  <td align="right"><?= _("UserId:") ?></td>
  <td><input type="text" name="auth[userid]" size="12" maxlength="256" value="<?=$userid?>" /></td>
</tr>
<tr>
  <td align="right"><?= _("Password:") ?></td>
  <td><input type="password" name="auth[passwd]" size="12" maxlength="256" /></td>
</tr>
<tr><td align="center" colspan="2">
  <?=Button("submit:", _("Sign In"), 'wikiaction')?>
  <?php if (!$require_level) { ?>
    <?=Button("submit:auth[cancel]", _("Cancel"), 'button')?>
  <?php } ?>
</td></tr>
</table>

<input type="hidden" name="auth[require_level]" value="<?=$require_level?>" />
<input type="hidden" name="auth[login]" value="1" />
<?= HiddenInputs($request->getArgs(), false, array('auth')) ?>
</form>

<script language="JavaScript" type="text/javascript">
<!-- // Really there's got to be a simpler way to do this....
function select_input (type) {
    var elements = document.forms['login'].elements;
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].type == type) {
            elements[i].focus();
            return;
        }
    }
}
select_input('<?= $userid ? "password" : "text" ?>');
//-->
</script>
