<?php include_once 'header.php';?>

<div class="row">
  <div class="col-md-12">
    <ul class="nav nav-pills nav-pills-warning">
      <li class="nav-item">
        <a class="nav-link" href="<?php echo JAK_rewrite::jakParseurl('settings');?>"><?php echo $jkl["hd9"];?></a>
      </li>
      <?php if ($jakosub['tickets'] && jak_get_access("support", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link" href="<?php echo JAK_rewrite::jakParseurl('settings', 'support');?>"><?php echo $jkl["hd10"];?></a>
        </li>
      <?php } if ($jakosub['faq'] && jak_get_access("faq", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link" href="<?php echo JAK_rewrite::jakParseurl('settings', 'faq');?>"><?php echo $jkl["hd11"];?></a>
        </li>
      <?php } if ($jakosub['blog'] && jak_get_access("blog", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link" href="<?php echo JAK_rewrite::jakParseurl('settings', 'blog');?>"><?php echo $jkl["hd12"];?></a>
        </li>
      <?php } ?>
      <li class="nav-item">
        <a class="nav-link active" href="<?php echo JAK_rewrite::jakParseurl('settings', 'email');?>"><?php echo $jkl["hd119"];?></a>
      </li>
      <?php if ($jakosub['tickets'] && jak_get_access("support", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link" href="<?php echo JAK_rewrite::jakParseurl('settings', 'phpimap');?>"><?php echo $jkl["hd43"];?></a>
        </li>
      <?php } ?>
    </ul>
  </div>
</div>
<hr>

<?php if ($errors) { ?>
  <div class="alert alert-danger">
    <?php if (isset($errors["e"])) echo $errors["e"];
    if (isset($errors["e1"])) echo $errors["e1"];
    if (isset($errors["e2"])) echo $errors["e2"];
    if (isset($errors["e3"])) echo $errors["e3"];
    if (isset($errors["e4"])) echo $errors["e4"];
    if (isset($errors["e5"])) echo $errors["e5"];
    if (isset($errors["e6"])) echo $errors["e6"];
    if (isset($errors["e7"])) echo $errors["e7"];?>
  </div>
<?php } if ($success) { ?>
  <div class="alert alert-success">
    <?php if (isset($success["e"])) echo $success["e"];?>
  </div>
<?php } ?>

<div class="row">
  <div class="col-md-12">

    <form method="post" class="jak_form" action="<?php echo $_SERVER['REQUEST_URI'];?>">

      <div class="card">
        <div class="card-header card-header-icon card-header-rose">
          <div class="card-icon">
            <i class="material-icons">email</i>
          </div>
          <h4 class="card-title"><?php echo $jkl["g212"];?></h4>
        </div>
        <div class="card-body">

          <div class="form-group">
            <label class="control-label" for="jak_smpt"><?php echo $jkl["g212"];?></label>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_smpt" value="0"<?php if (JAK_SMTP_MAIL == 0) echo "checked";?>> <?php echo $jkl["g204"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_smpt" value="1"<?php if (JAK_SMTP_MAIL == 1) echo "checked";?>> <?php echo $jkl["g205"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_smpt" value="2"<?php if (JAK_SMTP_MAIL == 2) echo "checked";?>> <?php echo $jkl["g362"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
          </div>

          <div class="form-group<?php if (isset($errors["e"])) echo " has-danger";?>">
            <label class="control-label" for="jak_smtpsender"><?php echo $jkl["g68"];?></label>
            <input type="text" name="jak_smtpsender" class="form-control" value="<?php echo JAK_SMTP_SENDER;?>" autocomplete="off">
          </div>

          <div id="smtp_options"<?php if (in_array(JAK_SMTP_MAIL,array(0,2))) echo ' style="display: none"';?>>

          <div class="form-group">
            <label class="control-label" for="jak_host"><?php echo $jkl["g206"];?></label>
            <input type="text" class="form-control" name="jak_host" value="<?php echo JAK_SMTPHOST;?>">
          </div>

          <div class="form-group<?php if (isset($errors["e3"])) echo " has-danger";?>">
            <label class="control-label" for="jak_port"><?php echo $jkl["g207"];?></label>
            <input type="text" name="jak_port" class="form-control" value="<?php echo JAK_SMTPPORT?>" placeholder="25">
          </div>

          <div class="form-group">
            <label class="control-label" for="jak_alive"><?php echo $jkl["g208"];?></label>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_alive" value="1"<?php if (JAK_SMTP_ALIVE == 1) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g19"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_alive" value="0"<?php if (JAK_SMTP_ALIVE == 0) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g18"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
          </div>

          <div class="form-group">
            <label class="control-label" for="jak_auth"><?php echo $jkl["g209"];?></label>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_auth" value="1"<?php if (JAK_SMTP_AUTH == 1) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g19"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
            <div class="form-check">
              <label class="form-check-label">
                <input class="form-check-input" type="radio" name="jak_auth" value="0"<?php if (JAK_SMTP_AUTH == 0) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g18"];?>
                <span class="circle">
                  <span class="check"></span>
                </span>
              </label>
            </div>
          </div>

          <div class="form-group">
            <label class="control-label" for="jak_prefix"><?php echo $jkl["g219"];?></label>
            <input type="text" name="jak_prefix" class="form-control" value="<?php echo JAK_SMTP_PREFIX;?>" placeholder="ssl/tls/true/false">
          </div>

          <div class="form-group">
            <label class="control-label" for="jak_smtpusername"><?php echo $jkl["g210"];?></label>
            <input type="text" name="jak_smtpusername" class="form-control" value="<?php echo JAK_SMTPUSERNAME;?>" autocomplete="off">
          </div>

          <div class="form-group">
            <label class="control-label" for="jak_smtppassword"><?php echo $jkl["g211"];?></label>
            <input type="password" name="jak_smtppassword" class="form-control" value="<?php echo JAK_SMTPPASSWORD;?>" autocomplete="off">
          </div>

          </div>

          <div id="oauth_options"<?php if (in_array(JAK_SMTP_MAIL,array(0,1))) echo ' style="display: none"';?>>

            <div class="form-group">
              <label class="control-label" for="jak_oauthprovider"><?php echo $jkl['g382'];?></label>
              <select name="jak_oauthprovider" class="selectpicker col-12" data-live-search="true">
                <option value="Google"<?php if (JAK_OAUTH_PROVIDER == "Google" ? ' selected="selected"' : '');?>>Google (Gmail)</option>
                <option value="Yahoo"<?php if (JAK_OAUTH_PROVIDER == "Yahoo" ? ' selected="selected"' : '');?>>Yahoo</option>
                <option value="Microsoft"<?php if (JAK_OAUTH_PROVIDER == "Microsoft" ? ' selected="selected"' : '');?>>Microsoft</option>
                <option value="Azure"<?php if (JAK_OAUTH_PROVIDER == "Azure" ? ' selected="selected"' : '');?>>Azure</option>
              </select>
            </div>

            <div class="form-group<?php if (isset($errors["e5"])) echo " has-danger";?>">
              <label class="control-label" for="jak_oauthclientid"><?php echo $jkl["g363"];?></label>
              <input type="text" name="jak_oauthclientid" class="form-control" value="<?php echo JAK_OAUTH_CLIENTID;?>">
            </div>

            <div class="form-group<?php if (isset($errors["e6"])) echo " has-danger";?>">
              <label class="control-label" for="jak_oauthsecret"><?php echo $jkl["g364"];?></label>
              <input type="password" name="jak_oauthsecret" class="form-control" value="<?php echo JAK_OAUTH_SECRET;?>" autocomplete="off">
            </div>

            <div class="form-group<?php if (isset($errors["e7"])) echo " has-danger";?>">
              <label class="control-label" for="jak_oauthtenantid"><?php echo $jkl["g380"];?></label>
              <input type="password" name="jak_oauthtenantid" class="form-control" value="<?php echo JAK_OAUTH_TENANTID;?>" autocomplete="off">
            </div>

            <div class="form-group">
              <label class="control-label" for="jak_oauthrefresh"><?php echo $jkl["g365"];?></label>
              <input type="password" name="jak_oauthrefresh" class="form-control" value="<?php echo JAK_OAUTH_REFRESH;?>" readonly>
            </div>

          </div>

          <div class="form-group">
            <button type="submit" name="refreshToken" class="btn btn-danger"><?php echo $jkl["g381"];?></button>
            <button type="submit" name="testMail" class="btn btn-success" id="sendTM"><i id="loader" class="fa fa-spinner fa-pulse"></i> <?php echo $jkl["g216"];?></button>
          </div>

        </div>
        <div class="card-footer">
          <button type="submit" name="save" class="btn btn-primary pull-right"><?php echo $jkl["g38"];?></button>
        </div>
      </div>

    </form>
  </div>
</div>
<?php include_once 'footer.php';?>
