<?php $music->terms = GetTerms(); ?>
<div class="container-fluid">
    <div>
        <h3>Manage Pages</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Pages</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage Pages</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 Term Pages</h6>
                    <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">Terms of Use (HTML Allowed)</label>
                                <textarea name="terms" id="terms" class="form-control" cols="30" rows="10"><?php echo $music->terms['terms'];?></textarea>
                                
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Privacy Policy (HTML Allowed)</label>
                                <textarea name="privacy" id="privacy" class="form-control" cols="30" rows="10"><?php echo $music->terms['privacy'];?></textarea>
                                
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">About (HTML Allowed)</label>
                                <textarea name="about" id="about" class="form-control" cols="30" rows="10"><?php echo $music->terms['about'];?></textarea>
                                
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">DMCA (HTML Allowed)</label>
                                <textarea name="dmca" id="dmca" class="form-control" cols="30" rows="10"><?php echo $music->terms['dmca'];?></textarea>
                                
                            </div>
                        </div>
                        <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 -->
</div>
<script>

$(function() {
    var form_add_settings = $('form.add-settings');
    form_add_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/save-terms',
        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 == "terms") {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#terms').value=tinymce.editors[$('#terms').attr('id')].getContent())));
                }
                if (arr[i].name == 'privacy') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#privacy').value=tinymce.editors[$('#privacy').attr('id')].getContent())));
                }
                if (arr[i].name == 'about') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#about').value=tinymce.editors[$('#about').attr('id')].getContent())));
                }
                if (arr[i].name == 'dmca') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#dmca').value=tinymce.editors[$('#dmca').attr('id')].getContent())));
                }
            }

          // delete arr[0];
          // delete arr[1];
          // delete arr[2];
          // delete arr[3];
          // arr.push({name:'terms', value:btoa(unescape(encodeURIComponent($('#terms').val())))});
          // arr.push({name:'privacy', value:btoa(unescape(encodeURIComponent($('#privacy').val())))});
          // arr.push({name:'about', value:btoa(unescape(encodeURIComponent($('#about').val())))});
          // arr.push({name:'dmca', value:btoa(unescape(encodeURIComponent($('#dmca').val())))});
        },
        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> Pages saved successfully</div>');
                setTimeout(function () {
                    $('.add-settings-alert').empty();
                }, 2000);
            } 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: '#terms',
          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: '#privacy',
          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: '#about',
          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: '#dmca',
          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>