<!-- Thông báo lỗi -->
<?php MyHelper::loadView('backend/cms_partials/error_message_view') ?>
<div class="row">
    <div class="col-lg-3">
        <div class="input-group text-center">
            <input class="form-control date-picker" id="input-date-picker" type="text" data-date-format="dd/mm/yyyy"
                   value="<?php echo date('d/m/Y', time()-86400)?>" readonly>
            <span class="input-group-addon">
                <i class="fa fa-calendar bigger-110"></i>
            </span>
        </div>
    </div>
    <div class="col-lg-1">
        <a href="" id="btn-export">
            <button class="btn btn-sm btn-warning"><i class="fa fa-download"></i> Export ra Excel</button>
        </a>
    </div>
</div>
<!-- /.row -->
<div class="space-6"></div>
<div class="row" >
    <div style="text-align: center" id="data-loading">
        <i class="fa fa-refresh fa-spin bigger-200"></i> Đang tải dữ liệu...
    </div>
    <?php MyHelper::loadView(
            'backend/cms_ranking/partials/title_report_violation',
            'Lưu ý: BXH ngày có từ 30/03/2020'
    )?>
    <div class="col-lg-12">
        <div id="div-response"></div>
    </div>
</div>
<!-- modal lịch sử lượt nghe -->
<?php MyHelper::loadView('backend/cms_ranking/partials/history_chart_modal')?>
<!-- modal báo cáo trùng bài hát -->
<?php MyHelper::loadView('backend/cms_ranking/partials/report_violation_modal')?>
<script type="text/javascript">
    //Thuc hien viec ve bieu do$data
    $(document).ready(function() {
        var url = '<?php echo base_url("backend/cmsRanking/listByDailyAjax"); ?>';

        // Tìm kiếm theo cú pháp
        var oldTimeout2 = '';
        $('#input-date-picker').change(function(){
            clearTimeout(oldTimeout2);
            oldTimeout2 = setTimeout(function(){
                loadDataByAjaxFromInput(url);
            }, 250);
        });
        // Xóa bộ lọc
        $('#delete-filter').click(function(){
            $("#input-date-picker").val('<?php echo date('d/m/Y', time()-86400)?>');
            changePagination('0');
            return false;

        });
        changePagination('0');
        updateExportLink();

        $('#input-date-picker').change(function () {
            updateExportLink();
        });

    });
    //Ham chung cho cac input
    function loadDataByAjaxFromInput(url){
        $('#data-loading').show();
        callAjax(0, url);
    }
    //Ham chung cho cac SelectBox
    function loadDataByAjaxFromSelectBox(id, url){
        $('#'+id).change(function(){
            $('#data-loading').show();
            callAjax(0, url);
        });
    }

    function loadDataByAjaxDateRange(dtFrom, dtTo, url){
        $('#data-loading').show();
        callAjax(0, url);
    }

    function changePagination(pageId) {
        $('#data-loading').show();
        var url = '<?php echo base_url("backend/cmsRanking/listByDailyAjax"); ?>';
        callAjax(pageId, url);
    }

    function callAjax(pageId, url) {
        var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
        var fByName = $("#input-date-picker").val();
        var dataReq = {
            csrf_name: csrf_value,
            fByName: fByName,
            pageId: pageId
        };
        //Ajax
        $.ajax({
            type: "POST",
            url: url,
            data: dataReq,
            dataType: "text",
            cache: false,
            success: function(data) {
                $('#div-response').html(data);
                $('#data-loading').hide();
            }
        });
    }

    function updateExportLink() {
        var date_picker = ($("#input-date-picker").val()) ? $("#input-date-picker").val() : null;
        if (date_picker) { date_picker = date_picker.replace(/\//g, '-') }
        var href = '<?php echo base_url("backend/cmsRanking/exportReport/daily"); ?>/' + date_picker;
        $('#btn-export').attr('href', href);
    }

    function showHistory(track_id, track_title) {
        $('#data-loading').show();
        $.ajax({
            type: "POST",
            url: '<?php echo base_url("backend/cmsRanking/getTrackHistoryAjax"); ?>',
            data: {
                csrf_name: '<?php echo $this->security->get_csrf_hash(); ?>',
                track_id: track_id,
                track_title: track_title
            },
            dataType: "HTML",
            cache: false,
            success: function(data) {
                $('#data-loading').hide();
                $('#track_title').html(track_title + ' (ID: ' + track_id + ')');
                $('#div-history-chart').html(data);
                $('#modal-track-chart').modal('show');
            },
            error: function () {
                $('#data-loading').hide();
            }
        });
    }
</script>
<!-- tải js xử lý cáo báo sai sót -->
<?php MyHelper::loadView('backend/cms_ranking/partials/js_process_report', 'DAILY')?>