{include file="header.tpl"}

{literal}
<script language=javascript>
function IsNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  if (sText == '') return false;
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

function checkform() {
  if (document.editform.fullname.value == '') {
    alert("Please type your full name!");
    document.editform.fullname.focus();
    return false;
  }
{/literal}
{if $settings.use_user_location == 1}
{literal}
  if (document.editform.address.value == '') {
    alert("Please enter your address!");
    document.editform.address.focus();
    return false;
  }
  if (document.editform.city.value == '') {
    alert("Please enter your city!");
    document.editform.city.focus();
    return false;
  }
  if (document.editform.state.value == '') {
    alert("Please enter your state!");
    document.editform.state.focus();
    return false;
  }
  if (document.editform.zip.value == '') {
    alert("Please enter your ZIP!");
    document.editform.zip.focus();
    return false;
  }
  if (document.editform.country.options[document.editform.country.selectedIndex].text == '--SELECT--') {
    alert("Please choose your country!");
    document.editform.country.focus();
    return false;
  }
{/literal}
{/if}
{literal}
  if (document.editform.password.value != document.editform.password2.value) {
    alert("Please check your password!");
    document.editform.password2.focus();
    return false;
  }
{/literal}
{if $settings.use_transaction_code}
{literal}
  if (document.editform.transaction_code.value != document.editform.transaction_code2.value) {
    alert("Please check your transaction code!");
    document.editform.transaction_code2.focus();
    return false;
  }
{/literal}
{/if}
{if $settings.usercanchangeemail == 1}
{literal}
  if (document.editform.email.value == '') {
    alert("Please enter your e-mail address!");
    document.editform.email.focus();
    return false;
  }
{/literal}
{/if}
{literal}
  for (i in document.editform.elements) {
    f = document.editform.elements[i];
    if (f.name && f.name.match(/^pay_account/)) {
      if (f.value == '') continue;
      var notice = f.getAttribute('data-validate-notice');
      var invalid = 0;
      if (f.getAttribute('data-validate') == 'regexp') {
        var re = new RegExp(f.getAttribute('data-validate-regexp'));
        if (!f.value.match(re)) {
          invalid = 1;
        }
      } else if (f.getAttribute('data-validate') == 'email') {
        var re = /^[^\@]+\@[^\@]+\.\w{2,4}$/;
        if (!f.value.match(re)) {
          invalid = 1;
        }
      }
      if (invalid) {
        alert('Invalid account format. Expected '+notice);
        f.focus();
        return false;
      }
    }
  }
  return true;
}
</script>
{/literal}

<div class="main-content">
  <div class="page-content">
    <div class="row">
      <div class="col-xl-12">
        <div class="card">
          <div class="card-body">
            <h4 class="card-title">Your account</h4>
            <br><br>

            {if $frm.say eq 'changed'}
              <div class="alert alert-success">Your account data has been updated successfully.</div>
            {/if}

            {if $errors}
              <div class="alert alert-danger">
                <ul class="mb-0">
                  {section name=e loop=$errors}
                    <li>
                      {if $errors[e] eq 'full_name'}Please enter your Full Name!{/if}
                      {if $errors[e] eq 'address'}Please enter your address!{/if}
                      {if $errors[e] eq 'city'}Please enter your city!{/if}
                      {if $errors[e] eq 'state'}Please enter your state!{/if}
                      {if $errors[e] eq 'zip'}Please enter your zip!{/if}
                      {if $errors[e] eq 'country'}Please choose your country!{/if}
                      {if $errors[e] eq 'username'}Please enter your username!{/if}
                      {if $errors[e] eq 'password'}Please enter a password!{/if}
                      {if $errors[e] eq 'password_confirm'}Please check your password!{/if}
                      {if $errors[e] eq 'password_too_small'}Password is too small, please enter at least {$settings.min_user_password_length} chars!{/if}
                      {if $errors[e] eq 'transaction_code'}Please enter the Transaction Code!{/if}
                      {if $errors[e] eq 'transaction_code_confirm'}Please check your Transaction Code!{/if}
                      {if $errors[e] eq 'transaction_code_too_small'}Transaction Code is too small, please enter at least {$settings.min_user_password_length} chars!{/if}
                      {if $errors[e] eq 'wrong_current_password'}You entered wrong current password{/if}
                      {if $errors[e] eq 'transaction_code_vs_password'}Transaction Code should be different than the Password!{/if}
                      {if $errors[e] eq 'invalid_transaction_code'}You have provided invalid Current Transaction Code!{/if}
                      {if $errors[e] eq 'email'}Please enter your e-mail!{/if}
                      {if $errors[e] eq 'turing_image'}Enter the verification code as it is shown in the corresponding box.{/if}
                      {if $errors[e] eq 'tfa_code'}Invalid 2FA code{/if}
                      {if $errors[e] eq 'invalid_account_format'}
                        {foreach from=$account_errors item=err}
                          {$err}
                        {/foreach}
                      {/if}
                    </li>
                  {/section}
                </ul>
              </div>
            {/if}

            <form action="" method="post" onsubmit="return checkform()" name="editform">
              <input type="hidden" name="a" value="edit_account">
              <input type="hidden" name="action" value="edit_account">
              <input type="hidden" name="say" value="">

              <table class="table table-sm">
                <tr>
                  <td>Account Name:</td>
                  <td>{$userinfo.username}</td>
                </tr>
                <tr>
                  <td>Registration date:</td>
                  <td>{$userinfo.date_register}</td>
                </tr>
                <tr>
                  <td>Your Full Name:</td>
                  <td><input type="text" name="fullname" value="{$userinfo.name|escape:'quotes'}" class="form-control form-control-sm" size="30"></td>
                </tr>

                <tr>
                  <td>New Password:</td>
                  <td><input type="password" name="password" value="" class="form-control form-control-sm" size="30"></td>
                </tr>
                <tr>
                  <td>Retype Password:</td>
                  <td><input type="password" name="password2" value="" class="form-control form-control-sm" size="30"></td>
                </tr>

                {foreach item=ps from=$pay_accounts}
                  <tr>
                    <td>Your {$ps.name} acc no:</td>
                    <td>
                      {if $settings.usercanchangeegoldacc == 0 && $ps.account != ''}
                        {$ps.account|escape:html}
                      {else}
                        <input type="text" class="form-control form-control-sm" size="30" name="pay_account[{$ps.id}]" value="{$frm.pay_account[$ps.id]|default:$ps.account|escape:html}" data-validate="{$ps.validate.func}" data-validate-{$ps.validate.func}="{$ps.validate[$ps.validate.func]}" data-validate-notice="{$ps.validate.notification|escape:html}">
                      {/if}
                    </td>
                  </tr>
                {/foreach}

                {foreach item=p from=$mpay_accounts}
                  {foreach item=ps from=$p.accounts}
                    <tr>
                      <td>Your {$p.name} {$ps.name}:</td>
                      <td>
                        {if $settings.usercanchangeegoldacc == 0 && $ps.value != ''}
                          {$ps.value|escape:html}
                        {else}
                          <input type="text" class="form-control form-control-sm" size="30" name="pay_account[{$p.id}][{$ps.name|escape:html}]" value="{$frm.pay_account[$p.id][$ps.name]|default:$ps.value|escape:html}">
                        {/if}
                      </td>
                    </tr>
                  {/foreach}
                {/foreach}

                <tr>
                  <td>Your E-mail address:</td>
                  <td>
                    {if $settings.usercanchangeemail == 1}
                      <input type="text" name="email" value="{$userinfo.email|escape:'quotes'}" class="form-control form-control-sm" size="30">
                    {else}
                      {$userinfo.email}
                    {/if}
                  </td>
                </tr>

                <tr>
                  <td></td>
                  <td><input type="submit" value="Change Account data" class="btn btn-sm btn-primary"></td>
                </tr>
              </table>
            </form>

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

{include file="footer.tpl"}
