
<?php $emails = GetHtmlEmails(); ?>
<div class="container-fluid">
    <div>
        <h3>Manage Emails</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Tools</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage Emails</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-8 col-md-8">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Edit System E-mails</h6>
                    <div class="alert alert-success">If you want to add translated texts you can use {{LANG key}} and replace key word with the key from Languages.</div>
                    <div class="add-settings-alert"></div>
                    <form class="add-settings" method="POST">
                         <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Confirm Account (HTML Allowed)</label>
                                <div class="alert alert-warning">Make sure to add {{USERNAME}} , {{CODE_URL}} , {{SITE_NAME}} in the right place</div>
                                <textarea name="confirm" id="confirm" class="form-control" cols="30" rows="10"><?php echo $emails['confirm'];?></textarea>
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Notification (HTML Allowed)</label>
                                <div class="alert alert-warning">Make sure to add {{uname}} , {{username}} , {{full_name}} , {{contents}} , {{site_name}} , {{user_link}} , {{notify_link}}  , {{c}} in the right place</div>
                                <textarea name="notification" id="notification" class="form-control" cols="30" rows="10"><?php echo $emails['notification'];?></textarea>
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Reset Password (HTML Allowed)</label>
                                <div class="alert alert-warning">Make sure to add {{username}} , {{code_url}} , {{site_name}} in the right place</div>
                                <textarea name="reset" id="reset" class="form-control" cols="30" rows="10"><?php echo $emails['reset'];?></textarea>
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Unusual Login (HTML Allowed)</label>
                                <div class="alert alert-warning">Make sure to add {{username}} , {{site_name}} , {{code}} , {{date}} , {{email}} , {{countryCode}} , {{ip_address}} , {{city}} in the right place</div>
                                <textarea name="unusual_login" id="unusual_login" class="form-control" cols="30" rows="10"><?php echo $emails['unusual_login'];?></textarea>
                            </div>
                        </div>
                        <br>
                        <input type="hidden" name="hash_id" value="<?php echo createMainSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Save</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

$(function() {
    var form_add_settings = $('form.add-settings');
    form_add_settings.ajaxForm({
        url: "{{CONFIG ajax_url}}/ap/update_html_emails",
        beforeSend: function() {
            form_add_settings.find('.waves-effect').text('Please wait..');
        },
        beforeSubmit : function(arr, $form, options){
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].name == "confirm") {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#confirm').value=tinymce.editors[$('#confirm').attr('id')].getContent())));
                }
                if (arr[i].name == 'notification') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#notification').value=tinymce.editors[$('#notification').attr('id')].getContent())));
                }
                if (arr[i].name == 'reset') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#reset').value=tinymce.editors[$('#reset').attr('id')].getContent())));
                }
                if (arr[i].name == 'unusual_login') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#unusual_login').value=tinymce.editors[$('#unusual_login').attr('id')].getContent())));
                }
            }
        },
        success: function(data) {
            if (data.status == 200) {
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.add-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Emails saved successfully</div>');
            } else if (data.status == 400) {
            $('.add-settings-alert').html('<div class="alert alert-danger">'+data.message+'</div>');
                setTimeout(function () {
                    $('.add-settings-alert').empty();
                }, 2000);
          }
          form_add_settings.find('.waves-effect').text('Save');
        }
    });
  tinymce.init({
      selector: '#confirm',
      height: 270,
      entity_encoding : "raw",
      paste_data_images: true,
      image_advtab: true,
      toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
      toolbar2: "print preview media | forecolor backcolor",
      plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "template paste textcolor colorpicker textpattern"
      ],
  });
  tinymce.init({
      selector: '#notification',
      height: 270,
      entity_encoding : "raw",
      paste_data_images: true,
      image_advtab: true,
      toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
      toolbar2: "print preview media | forecolor backcolor",
      plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "template paste textcolor colorpicker textpattern"
      ],
  });
  tinymce.init({
      selector: '#username',
      height: 270,
      entity_encoding : "raw",
      paste_data_images: true,
      image_advtab: true,
      toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
      toolbar2: "print preview media | forecolor backcolor",
      plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "template paste textcolor colorpicker textpattern"
      ],
  });
  tinymce.init({
      selector: '#unusual_login',
      height: 270,
      entity_encoding : "raw",
      paste_data_images: true,
      image_advtab: true,
      toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
      toolbar2: "print preview media | forecolor backcolor",
      plugins: [
        "advlist autolink lists link image charmap print preview hr anchor pagebreak",
        "searchreplace wordcount visualblocks visualchars code fullscreen",
        "insertdatetime media nonbreaking save table contextmenu directionality",
        "template paste textcolor colorpicker textpattern"
      ],
  });
});
</script>