|
74 | 74 | $fragmentsearch->setVar('value', $searchvalue); |
75 | 75 | $cmsearch = $fragmentsearch->parse('core/form/search.php'); |
76 | 76 |
|
| 77 | +$statsBtn = '<button class="btn btn-info" id="btn-consent-stats" style="margin-right: 10px;"><i class="rex-icon fa-bar-chart"></i> ' . rex_i18n::msg('consent_manager_stats') . '</button>'; |
| 78 | + |
77 | 79 | $fragment = new rex_fragment(); |
78 | 80 | $fragment->setVar('title', rex_i18n::msg('consent_manager_thead_title')); |
79 | | -$fragment->setVar('options', $cmsearch, false); |
| 81 | +$fragment->setVar('options', '<div style="display:flex; justify-content:flex-end; align-items:center;">' . $statsBtn . $cmsearch . '</div>', false); |
80 | 82 | $fragment->setVar('content', $list->get(), false); |
81 | 83 | echo $fragment->parse('core/page/section.php'); |
| 84 | + |
| 85 | +?> |
| 86 | +<!-- Modal --> |
| 87 | +<div class="modal fade" id="consent-stats-modal" tabindex="-1" role="dialog"> |
| 88 | + <div class="modal-dialog modal-lg" role="document"> |
| 89 | + <div class="modal-content"> |
| 90 | + <div class="modal-header"> |
| 91 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
| 92 | + <h4 class="modal-title"><?php echo rex_i18n::msg('consent_manager_stats_title'); ?></h4> |
| 93 | + </div> |
| 94 | + <div class="modal-body" id="consent-stats-body"> |
| 95 | + <div class="text-center"><i class="rex-icon fa-spinner fa-spin fa-3x"></i></div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | +</div> |
| 100 | + |
| 101 | +<script nonce="<?= rex_response::getNonce() ?>"> |
| 102 | +$(document).on('click', '#btn-consent-stats', function() { |
| 103 | + $('#consent-stats-modal').modal('show'); |
| 104 | + loadConsentStats(); |
| 105 | +}); |
| 106 | + |
| 107 | +function loadConsentStats() { |
| 108 | + $('#consent-stats-body').html('<div class="text-center"><i class="rex-icon fa-spinner fa-spin fa-3x"></i></div>'); |
| 109 | + $.ajax({ |
| 110 | + url: 'index.php?rex-api-call=consent_manager_stats&days=30', |
| 111 | + dataType: 'json', |
| 112 | + success: function(data) { |
| 113 | + renderStats(data); |
| 114 | + }, |
| 115 | + error: function() { |
| 116 | + $('#consent-stats-body').html('<div class="alert alert-danger"><?php echo rex_i18n::msg('consent_manager_stats_error'); ?></div>'); |
| 117 | + } |
| 118 | + }); |
| 119 | +} |
| 120 | + |
| 121 | +function renderStats(data) { |
| 122 | + var html = ''; |
| 123 | + |
| 124 | + // Summary |
| 125 | + html += '<div class="row"><div class="col-md-12"><h4><?php echo rex_i18n::msg('consent_manager_stats_total'); ?> ' + data.total + '</h4></div></div>'; |
| 126 | + html += '<hr>'; |
| 127 | + |
| 128 | + // Cookies |
| 129 | + html += '<div class="row"><div class="col-md-6">'; |
| 130 | + html += '<h5><?php echo rex_i18n::msg('consent_manager_stats_top_cookies'); ?></h5>'; |
| 131 | + html += '<table class="table table-striped table-condensed">'; |
| 132 | + html += '<thead><tr><th><?php echo rex_i18n::msg('consent_manager_stats_service'); ?></th><th><?php echo rex_i18n::msg('consent_manager_stats_count'); ?></th><th>%</th></tr></thead><tbody>'; |
| 133 | + |
| 134 | + $.each(data.cookies, function(uid, count) { |
| 135 | + var percent = data.total > 0 ? Math.round((count / data.total) * 100) : 0; |
| 136 | + html += '<tr>'; |
| 137 | + html += '<td>' + uid + '</td>'; |
| 138 | + html += '<td>' + count + '</td>'; |
| 139 | + html += '<td><div class="progress" style="margin-bottom:0"><div class="progress-bar progress-bar-info" role="progressbar" style="width: ' + percent + '%;">' + percent + '%</div></div></td>'; |
| 140 | + html += '</tr>'; |
| 141 | + }); |
| 142 | + html += '</tbody></table>'; |
| 143 | + html += '</div>'; |
| 144 | + |
| 145 | + // Daily |
| 146 | + html += '<div class="col-md-6">'; |
| 147 | + html += '<h5><?php echo rex_i18n::msg('consent_manager_stats_history'); ?></h5>'; |
| 148 | + html += '<table class="table table-striped table-condensed">'; |
| 149 | + html += '<thead><tr><th><?php echo rex_i18n::msg('consent_manager_stats_date'); ?></th><th><?php echo rex_i18n::msg('consent_manager_stats_count'); ?></th></tr></thead><tbody>'; |
| 150 | + $.each(data.daily, function(i, day) { |
| 151 | + html += '<tr>'; |
| 152 | + html += '<td>' + day.date + '</td>'; |
| 153 | + html += '<td>' + day.count + '</td>'; |
| 154 | + html += '</tr>'; |
| 155 | + }); |
| 156 | + html += '</tbody></table>'; |
| 157 | + html += '</div></div>'; |
| 158 | + |
| 159 | + $('#consent-stats-body').html(html); |
| 160 | +} |
| 161 | +</script> |
| 162 | +<?php |
0 commit comments