<div class="container-fluid">
    <div>
        <h3>Manage Website Ads</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Advertisements</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage Website Ads</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Manage Website Ads</h6>
                    <div class="ads-settings-alert"></div>
                    <form class="ads-settings" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Header <small>(Appears on discover, top music and new music pages under the nav bar)</small></label>
                                <textarea name="header" id="header" class="form-control" cols="30" rows="5"><?php echo GetAd('header', true);?></textarea>
                                
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Footer <small>(Appears on all pages right before the footer)</small></label>
                                <textarea name="footer" id="footer" class="form-control" cols="30" rows="5"><?php echo GetAd('footer', true);?></textarea>
                                
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Sidebar <small>(Appears on track page, and user profile.)</small></label>
                                <textarea name="side_bar" id="side_bar" class="form-control" cols="30" rows="5"><?php echo GetAd('side_bar', true);?></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 -->
<script>
$(function() {
    var form_ads_settings = $('form.ads-settings');
    form_ads_settings.ajaxForm({
        url: '{{CONFIG ajax_url}}/ap/update-ads',
        beforeSend: function() {
            form_ads_settings.find('.waves-effect').text('Please wait..');
        },
        beforeSubmit : function(arr, $form, options){
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].name == "header") {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#header').val())));
                }
                if (arr[i].name == 'footer') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#footer').val())));
                }
                if (arr[i].name == 'side_bar') {
                    arr[i].value = btoa(unescape(encodeURIComponent($('#side_bar').val())));
                }
            }
          // delete arr[0];
          // delete arr[1];
          // delete arr[2];
          // arr.push({name:'header', value:btoa(unescape(encodeURIComponent($('#header').val())))});  
          // arr.push({name:'footer', value:btoa(unescape(encodeURIComponent($('#footer').val())))});
          // arr.push({name:'side_bar', value:btoa(unescape(encodeURIComponent($('#side_bar').val())))});
        },
        success: function(data) {
            if (data.status == 200) {
                form_ads_settings.find('.waves-effect').text('Save');
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.ads-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Ads updated successfully</div>');
                setTimeout(function () {
                    $('.ads-settings-alert').empty();
                }, 2000);
            }
        }
    });
});
</script>