<?php
/** @var User $usr */
?>
<h1><?php echo t('Reset Password');?> <a
    href="<?php echo ctrl()->getPageLink();?>" class="icon-refresh"></a>
</h1>
<div
  style="margin: 10px; padding: 10px; border: solid gray 2px; border-radius: 5px;">
<?php
if ($result)
{
  ?>
  <h2><?php echo t('Password has been reset');?></h2>
  <h3><?php  echo t("Username");?>: <span style="color: blue;"
      title="<?php echo $usr->getFullName();?>"><?php echo $usr->username; ?></span>
  </h3>
  <h3><?php  echo t("New password");?>: <?php
  $passwordCharIndex = 0;
  foreach ( str_split ( $newPassword ) as $passwordChar )
  {
    echo "<span id=\"pwdchr_visible_{$passwordCharIndex}\" class=\"pwdchr_visible\" style=\"color: green; font-family: monospace; margin: 3px; padding: 3px; border: solid silver 1px; border-radius: 2px;\">$passwordChar</span>";
    echo "<span id=\"pwdchr_hidden_{$passwordCharIndex}\" class=\"pwdchr_hidden\" style=\"color: black; font-family: monospace; margin: 3px; padding: 3px; border: solid silver 1px; border-radius: 2px;\">*</span>";
    $passwordCharIndex ++;
  }
  ?>
  </h3>
  <script type="text/javascript">
  passwordShown = false;
  function hidePassword(showCmd)
  {
    if(showCmd)
    {
      $('.pwdchr_hidden').show();
      $('.pwdchr_visible').hide();
      passwordShown = true;
    }
    else
    {
      $('.pwdchr_hidden').hide();
      $('.pwdchr_visible').show();
      passwordShown = false;
    }
  }
  function switchPasswordVisibility()
  {
    hidePassword(!passwordShown);
  }
  switchPasswordVisibility();
  </script>
  <a href="#" onclick="javascript:switchPasswordVisibility();">Show/Hide
    password</a><br />
<?php
  if (! isEmptyOrWhitespace ( $usr->email ))
  {
    echo CHtml::mailto ( "Send password to <b>$usr->email</b>", $usr->email . "?subject=[Event Server] New password for user {$usr->username}&body=New password for user {$usr->username} is: {$newPassword}" );
  }
}
else
{
  echo '<h3><span style="color: red;">' . t ( "Error" ) . "</span></h3>";
  var_dump_html ( $usr->errors );
}
?>
</div>