<?php $pt->terms = PT_GetTerms();?>
<div class="container-fluid">
    <div class="block-header">
        <h2>Pages > Manage Pages</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-8 col-md-8">
            <div class="card">
                <div class="header">
                    <h2>Edit Term Pages</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success add-settings-alert"></div>
                    <form class="add-settings" method="POST">
                         <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="terms_of_use" id="terms_of_use" class="form-control" cols="30" rows="10"><?php echo $pt->terms['terms_of_use'];?></textarea>
                                <label class="form-label">Terms of Use (HTML Allowed)</label>
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="privacy_policy" id="privacy_policy" class="form-control" cols="30" rows="10"><?php echo $pt->terms['privacy_policy'];?></textarea>
                                <label class="form-label">Privacy Policy (HTML Allowed)</label>
                            </div>
                        </div>
                        <br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="about" id="about" class="form-control" cols="30" rows="10"><?php echo $pt->terms['about'];?></textarea>
                                <label class="form-label">About (HTML Allowed)</label>
                            </div>
                        </div>
                        <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: '{{LINK aj/ap/save-terms}}',
        beforeSend: function() {
            form_add_settings.find('.waves-effect').text('Please wait..');
        },
        beforeSubmit : function(arr, $form, options){
          delete arr[0];
          delete arr[1];
          delete arr[2];
          arr.push({name:'terms_of_use', value:btoa(unescape(encodeURIComponent($('#terms_of_use').val())))}); 
          arr.push({name:'privacy_policy', value:btoa(unescape(encodeURIComponent($('#privacy_policy').val())))});
          arr.push({name:'about', value:btoa(unescape(encodeURIComponent($('#about').val())))});
        },
        success: function(data) {
            if (data.status == 200) {
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.add-settings-alert').html('<i class="fa fa-check"></i> Pages saved successfully');
            } else if (data.status == 400) {
	          alert(data.message);
	        }
	        form_add_settings.find('.waves-effect').text('Save');
        }
    });
});
</script>