<?php defined('_JEXEC') or die; ?>

<?php if ((int)$user->id > 0) : ?>
  <h2><?= JText::_('MOD_ARCHLINE_NEWSLETTER_SETTINGS') ?></h2>

  <form name="newsletterSettings" id="newsletterSettings" method="POST">
    <div class="container">
      <?php if (is_array($newsletterEmails) && count($newsletterEmails)) : ?>
        <p><?= JText::_('MOD_ARCHLINE_NEWSLETTER_TEXT1') ?></p>
        <?php foreach ($newsletterEmails as $email) : ?>
          <div class="row">
            <div class="col-10 col-sm-10 col-md-10 col-lg-6 col-xl-6"><label for="newsletter_<?= $email->u_emails_id ?>" title="<?= JText::_('MOD_ARCHLINE_NEWSLETTER_LEGEND') ?>"><?= $email->email ?></label></div>
            <div class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1"><?= JText::_('MOD_ARCHLINE_NEWSLETTER_ENABLED') ?></div>
            <div class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1"><input type="checkbox" name="newsletter[]" id="newsletter_<?= $email->u_emails_id ?>" value="<?= $email->u_emails_id ?>" <?= ($email->newsletter == 1 ? ' checked="checked" ' : '') ?> /></div>

            <?php if (isset($kulcsok) && is_array($kulcsok) && count($kulcsok) && count($newsletterEmails) == 1) : ?>
              <div class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1"><button type="button" class="btn btn-danger btn-xs disabled"><?= JText::_('MOD_ARCHLINE_DEL_EMAIL') ?></button></div>
            <?php else : ?>
              <div class="col-1 col-sm-1 col-md-1 col-lg-1 col-xl-1"><button type="button" class="btn btn-danger btn-xs" onclick="javascript:jQuery('#del_email').val('<?= $email->u_emails_id ?>');jQuery('#newsletterSettings').submit();"><?= JText::_('MOD_ARCHLINE_DEL_EMAIL') ?></button></div>
            <?php endif; ?>

          </div>
        <?php endforeach; ?>
      <?php endif; ?>

      <?php if (isset($kulcsok) && is_array($kulcsok) && count($kulcsok) && count($newsletterEmails) == 1) : ?>
        <p><?= JText::_('MOD_ARCHLINE_LAST_EMAIL_NOTICE') ?></p>
      <?php endif; ?>

      <div class="row">
        <div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6 form-group"><input type="text" name="new_email" id="new_email" value="" placeholder="<?= JText::_('MOD_ARCHLINE_NEW_EMAIL') ?>" class="form-control" /></div>
      </div>
    </div>
    <p><button type="submit" class="btn btn-success"><?= JText::_('JSAVE') ?></button></p>
    <input type="hidden" name="del_email" id="del_email" value="" />
    <input type="hidden" name="nl" id="nl" value="nl" />
  </form>

  <p><?= JText::_('MOD_ARCHLINE_NEWSLETTER_TEXT2') ?></p>
  <!--p><?= JText::sprintf('MOD_ARCHLINE_NEWSLETTER_TEXT3', 'info@cadline.hu', 'info@cadline.hu'/*JFactory::getConfig()->get('mailfrom'),JFactory::getConfig()->get('mailfrom')*/) ?></p-->

  <hr />
  <h2><?= JText::_('MOD_ARCHLINE_PERSONAL_DATA_SETTINGS') ?></h2>
  <form name="personalSettings" id="personalSettings" method="POST" class="needs-validation" novalidate>
    <div class="container">
      <div class="row">
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_USERNAME') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $user->username ?></div>
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_COUNTRY') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group">
          <select name="nCtrID" id="nCtrID" class="form-control" required>
            <?php foreach ($countries as $country) echo '<option value="' . $country->ctrID . '"' . ($crmUser->nCtrID == $country->ctrID ? ' selected="selected"' : '') . '>' . $country->ctrNameEng . '</option>'; ?>
          </select>
        </div>
      </div>
      <div class="row">
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_NAME') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group"><input type="text" name="strName" id="strName" value="<?= $crmUser->strName ?>" class="form-control" required><!--div class="invalid-feedback">Please provide a valid name.</div--></div>
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_PHONE') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group"><input type="text" name="strTel" id="strTel" value="<?= $crmUser->strTel ?>" class="form-control" required /></div>
      </div>
      <div class="row">
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_CITY') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group"><input type="text" name="strCity" id="strCity" value="<?= $crmUser->strCity ?>" class="form-control" required /></div>
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_PROFESSION') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group">
          <select name="nUserProf" id="nUserProf" class="form-control" required>
            <?php foreach ($profs as $prof) echo '<option value="' . $prof->proID . '" ' . ($crmUser->nUserProf == $prof->proID ? 'selected="selected"' : '') . '>' . $prof->proName_Eng . '</option>'; ?>
          </select>
        </div>
      </div>
    </div>
    <p><button type="submit" class="btn btn-success"><?= JText::_('JSAVE') ?></button></p>
    <input type="hidden" name="ps" id="ps" value="ps" />
  </form>

  <hr />
  <h2><?= JText::_('MOD_ARCHLINE_INVOICE_DATA_SETTINGS') ?></h2>
  <div class="container">
    <div class="row">
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_NAME') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strInvoiceName ?></div>
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_COUNTRY') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4">
        <?php foreach ($countries as $country) {
          if ($crmUser->nInvoiceCtrID == $country->ctrID) {
            echo $country->ctrNameEng;
            break;
          }
        } ?>
      </div>
    </div>
    <div class="row">
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_EMAIL') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strInvoiceEMail ?></div>
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_ZIP') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strInvoiceZip ?></div>
    </div>
    <div class="row">
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_TAXNUMBER') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strTaxNumber ?></div>
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_CITY') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strInvoiceCity ?></div>
    </div>
    <div class="row">
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_EACCOUNT') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= ($crmUser->strInvoiceEAccount == 'Y' ? JText::_('JYES') : JText::_('JNO')) ?></div>
      <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_ADDRESS') ?>:</b></div>
      <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4"><?= $crmUser->strInvoiceAddress ?></div>
    </div>
  </div>
  <p><a href="mailto:<?= JText::_('MOD_ARCHLINE_EDIT_INVOICE') ?>?subject=<?= JText::_('MOD_ARCHLINE_SUBJECT') ?>"><button type="button" class="btn btn-info"><?= JText::_('MOD_ARCHLINE_ASK_EDIT') ?></button></a></p>

  <hr />
  <h2><?= JText::_('MOD_ARCHLINE_PASSWORD_CHANGE') ?></h2>
  <p><?= JText::_('MOD_ARCHLINE_PASSWORD_CHANGE_TEXT1') ?></p>
  <form name="passwordChange" id="passwordChange" method="POST">
    <div class="container">
      <div class="row">
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_PASSWORD') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group"><input type="password" name="password1" id="password1" value="" autocomplete="off" class="form-control" /></div>
      </div>
      <div class="row">
        <div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2"><b><?= JText::_('MOD_ARCHLINE_PASSWORD2') ?>:</b></div>
        <div class="col-12 col-sm-12 col-md-8 col-lg-4 col-xl-4 form-group"><input type="password" name="password2" id="password2" value="" autocomplete="off" class="form-control" /></div>
      </div>
    </div>
    <p>
      <button type="submit" class="btn btn-success"><?php echo JText::_('MOD_ARCHLINE_PASSWORD_SAVE'); ?></button>
      <input type="hidden" name="pw" id="pw" value="pw" />
    </p>
  </form>

  <? if (isset($kulcsok) && is_array($kulcsok) && count($kulcsok)) : ?>
    <hr />
    <h2><?= JText::_('MOD_ARCHLINE_PROGRAM_LEGEND') ?></h2>
    <!--<p><a href="<?= ($lang == 'hu-HU' ? '/oktatas/aktivalas' : '/education/registration-and-activation') ?>?ml=1" title="<?= JText::_('MOD_ARCHLINE_SHOW_FAQ_LEGEND') ?>" class="modal_link btn btn-info" data-modal-width="95%" data-modal-height="80%"><?= JText::_('MOD_ARCHLINE_SHOW_FAQ_LEGEND') ?></a></p>-->
    <div class="alusers">
      <?php foreach ($kulcsok as $kulcs) : ?>
        <dl>
          <dt><?= JText::_('MOD_ARCHLINE_KEY_NUMBER_LEGEND'); ?></dt>
          <dd><?= $kulcs->kulcs_kod; ?></dd><br />

          <?php
          $aktiv = $inaktiv = "";
          if (is_array($kulcs->programok) && count($kulcs->programok)) {
            foreach ($kulcs->programok as $program) {
              if (strpos($program->prPass, 'L') !== false) {
                $program->verName .= ' Live';
              }
              if (substr($program->prPass, 0, 2) == 99) {
                $program->typeName = "Non-Profit";
              }
              $class = ($program->prStat == 0 ? "aktiv" : "inaktiv");

              if ($program->prStat == 0) {
                $aktiv .= '<dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_VERSION_LEGEND') . '</dt>
                <dd class="' . $class . '">' . $program->verName . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_PROGRAM_TYPE_LEGEND') . '</dt>
                <dd class="' . $class . '">' . $program->typeName . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_SERIAL_NUMBER_LEGEND') . '</dt>
                <dd class="' . $class . '">' . ($program->prSellDate != '0000-00-00' ? $program->prPass : '') . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_ACTIVATION_NUMBER_LEGEND') . '</dt>
                <dd class="' . $class . '">' . ($program->prSellDate != '0000-00-00' ? $program->prActCode : '') . '</dd><br />';
                if (!empty($program->modulok)) {
                  $aktiv .= '<dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_MODULES_LEGEND') . '</dt>';
                  $aktiv .= '<dd class="' . $class . '">';
                  foreach ($program->modulok as $modul) {
                    $aktiv .= ($lang == 'hu-HU' ? $modul->mdtName : $modul->mdtNameEng) . '<br />';
                    $aktiv .= ($program->prSellDate != '0000-00-00' ? $modul->mdCode : '') . '<br />';
                  }
                  $aktiv .= '</dd><br />';
                }
                $aktiv .= '<br />';
              } else {
                $inaktiv .= '<dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_VERSION_LEGEND') . '</dt>
                <dd class="' . $class . '">' . $program->verName . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_PROGRAM_TYPE_LEGEND') . '</dt>
                <dd class="' . $class . '">' . $program->typeName . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_SERIAL_NUMBER_LEGEND') . '</dt>
                <dd class="' . $class . '">' . ($program->prSellDate != '0000-00-00' ? $program->prPass : '') . '</dd><br />
                <dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_ACTIVATION_NUMBER_LEGEND') . '</dt>
                <dd class="' . $class . '">' . ($program->prSellDate != '0000-00-00' ? $program->prActCode : '') . '</dd><br />';

                if (!empty($program->modulok)) {
                  $inaktiv .= '<dt class="' . $class . '">' . JText::_('MOD_ARCHLINE_MODULES_LEGEND') . '</dt>';
                  $inaktiv .= '<dd class="' . $class . '">';
                  foreach ($program->modulok as $modul) {
                    $inaktiv .= ($lang == 'hu-HU' ? $modul->mdtName : $modul->mdtNameEng) . '<br />';
                    $inaktiv .= ($program->prSellDate != '0000-00-00' ? $modul->mdCode : '') . '<br />';
                  }
                  $inaktiv .= '</dd><br />';
                }
                $inaktiv .= '<br />';
              }
            }
          }
          ?>

          <?= $aktiv ?>

          <?php if ($inaktiv > '') : ?>
            <dd><input type="button" name="showAll" value="<?= JText::_('MOD_ARCHLINE_SHOW_ALL_LEGEND') ?>" onclick="javascript:atvalt('<?= $kulcs->kulcs_kod ?>');" class="btn btn-primary" /></dd><br /><br />
            <div id="inaktiv_<?= $kulcs->kulcs_kod ?>" style="display:none;">
              <?= $inaktiv ?>
            </div>
          <?php endif; ?>
        </dl>
      <? endforeach; ?>
    </div>

    <script type="text/javascript">
      function atvalt(id) {
        jQuery("#inaktiv_" + id).toggle("fast");
      }
    </script>
  <? endif; ?>
<? endif; ?>
<script src="/maintenance/js/jquery.min.js"></script>
<script type="text/javascript">
  // Example starter JavaScript for disabling form submissions if there are invalid fields
  (function() {
    'use strict';
    window.addEventListener('load', function() {
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
      var forms = document.getElementsByClassName('needs-validation');
      // Loop over them and prevent submission
      var validation = Array.prototype.filter.call(forms, function(form) {
        form.addEventListener('submit', function(event) {
          if (form.checkValidity() === false) {
            event.preventDefault();
            event.stopPropagation();
          }
          form.classList.add('was-validated');
        }, false);
      });
    }, false);
  })();

  $(document).ready(function() {
    $('[id^=strZip]').keypress(validateNumber);
    $('[id^=strTel]').keypress(validateNumber2);
  });

  function validateNumber(event) {
    var key = window.event ? event.keyCode : event.which;

    if (event.keyCode === 8 || event.keyCode === 46) {
      return true;
    } else if (event.keyCode === 190) {
      return false;
    } else if (key < 48 || key > 57) {
      return false;
    } else {
      return true;
    }
  };

  function validateNumber2(event) {
    var key = window.event ? event.keyCode : event.which;

    if (key >= 65 && key <= 90) {
      return false;
    } else {
      return true;
    }
  };
</script>