| 1 |
<?php |
| 2 |
/** |
| 3 |
* Activity Log - Main Admin Layout. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
$activity_log = \King_Addons\Activity_Log::instance(); |
| 13 |
$options = $activity_log->get_options(); |
| 14 |
$kpis = $activity_log->get_kpis(); |
| 15 |
$is_pro = $activity_log->is_pro(); |
| 16 |
|
| 17 |
// Get current tab |
| 18 |
$current_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'dashboard'; |
| 19 |
$tabs = [ |
| 20 |
'dashboard' => __('Dashboard', 'king-addons'), |
| 21 |
'logs' => __('Logs', 'king-addons'), |
| 22 |
'settings' => __('Settings', 'king-addons'), |
| 23 |
'export' => __('Export', 'king-addons'), |
| 24 |
]; |
| 25 |
|
| 26 |
// Get saved theme (default to dark) |
| 27 |
$saved_theme = get_user_meta(get_current_user_id(), 'ka_activity_log_theme', true); |
| 28 |
$is_light = ($saved_theme === 'light'); |
| 29 |
?> |
| 30 |
<div class="ka-al-wrap"> |
| 31 |
<!-- Header --> |
| 32 |
<div class="ka-al-header"> |
| 33 |
<div class="ka-al-header-left"> |
| 34 |
<h1 class="ka-al-title"><?php esc_html_e('Activity Log', 'king-addons'); ?></h1> |
| 35 |
<p class="ka-al-subtitle"><?php esc_html_e('Monitor and audit all site activities', 'king-addons'); ?></p> |
| 36 |
</div> |
| 37 |
<div class="ka-al-header-actions"> |
| 38 |
<button type="button" class="ka-al-theme-toggle" id="ka-al-theme-toggle" |
| 39 |
title="<?php esc_attr_e('Toggle theme', 'king-addons'); ?>"> |
| 40 |
<svg class="ka-al-icon-sun" xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="none" |
| 41 |
viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> |
| 42 |
<path stroke-linecap="round" stroke-linejoin="round" |
| 43 |
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /> |
| 44 |
</svg> |
| 45 |
<svg class="ka-al-icon-moon" xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="none" |
| 46 |
viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" style="display:none;"> |
| 47 |
<path stroke-linecap="round" stroke-linejoin="round" |
| 48 |
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" /> |
| 49 |
</svg> |
| 50 |
</button> |
| 51 |
<?php if (!$is_pro): ?> |
| 52 |
<a href="https://kingaddons.com/pricing/?utm_source=kng-activity-log&utm_medium=plugin&utm_campaign=kng" |
| 53 |
class="ka-al-btn ka-al-btn-primary" target="_blank"> |
| 54 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="none" viewBox="0 0 24 24" |
| 55 |
stroke="currentColor" stroke-width="2"> |
| 56 |
<path stroke-linecap="round" stroke-linejoin="round" d="M13 10V3L4 14h7v7l9-11h-7z" /> |
| 57 |
</svg> |
| 58 |
<?php esc_html_e('Upgrade to Pro', 'king-addons'); ?> |
| 59 |
</a> |
| 60 |
<?php endif; ?> |
| 61 |
</div> |
| 62 |
</div> |
| 63 |
|
| 64 |
<!-- Navigation Tabs --> |
| 65 |
<nav class="ka-al-nav"> |
| 66 |
<?php foreach ($tabs as $tab_id => $tab_label): ?> |
| 67 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-activity-log&tab=' . $tab_id)); ?>" |
| 68 |
class="ka-al-nav-item <?php echo $current_tab === $tab_id ? 'active' : ''; ?>"> |
| 69 |
<?php echo esc_html($tab_label); ?> |
| 70 |
</a> |
| 71 |
<?php endforeach; ?> |
| 72 |
</nav> |
| 73 |
|
| 74 |
<!-- Tab Content --> |
| 75 |
<div class="ka-al-content"> |
| 76 |
<?php |
| 77 |
switch ($current_tab) { |
| 78 |
case 'logs': |
| 79 |
require_once __DIR__ . '/tab-logs.php'; |
| 80 |
break; |
| 81 |
case 'settings': |
| 82 |
require_once __DIR__ . '/tab-settings.php'; |
| 83 |
break; |
| 84 |
case 'export': |
| 85 |
require_once __DIR__ . '/tab-export.php'; |
| 86 |
break; |
| 87 |
default: |
| 88 |
require_once __DIR__ . '/tab-dashboard.php'; |
| 89 |
break; |
| 90 |
} |
| 91 |
?> |
| 92 |
</div> |
| 93 |
|
| 94 |
<!-- Event Drawer (for details) --> |
| 95 |
<div class="ka-al-drawer" id="ka-al-drawer"> |
| 96 |
<div class="ka-al-drawer-backdrop"></div> |
| 97 |
<div class="ka-al-drawer-panel"> |
| 98 |
<div class="ka-al-drawer-header"> |
| 99 |
<h3><?php esc_html_e('Event Details', 'king-addons'); ?></h3> |
| 100 |
<button type="button" class="ka-al-drawer-close" |
| 101 |
aria-label="<?php esc_attr_e('Close', 'king-addons'); ?>"> |
| 102 |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24" |
| 103 |
stroke="currentColor" stroke-width="2"> |
| 104 |
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /> |
| 105 |
</svg> |
| 106 |
</button> |
| 107 |
</div> |
| 108 |
<div class="ka-al-drawer-body"> |
| 109 |
<!-- Content loaded via AJAX --> |
| 110 |
</div> |
| 111 |
</div> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
|
| 115 |
<script> |
| 116 |
(function () { |
| 117 |
// Theme toggle functionality |
| 118 |
var body = document.body; |
| 119 |
var toggle = document.getElementById('ka-al-theme-toggle'); |
| 120 |
var sunIcon = toggle.querySelector('.ka-al-icon-sun'); |
| 121 |
var moonIcon = toggle.querySelector('.ka-al-icon-moon'); |
| 122 |
var savedTheme = '<?php echo esc_js($saved_theme); ?>'; |
| 123 |
|
| 124 |
// Apply saved theme on load |
| 125 |
if (savedTheme === 'light') { |
| 126 |
body.classList.add('ka-al-light'); |
| 127 |
sunIcon.style.display = 'none'; |
| 128 |
moonIcon.style.display = 'block'; |
| 129 |
} |
| 130 |
|
| 131 |
toggle.addEventListener('click', function () { |
| 132 |
body.classList.toggle('ka-al-light'); |
| 133 |
var isLight = body.classList.contains('ka-al-light'); |
| 134 |
|
| 135 |
sunIcon.style.display = isLight ? 'none' : 'block'; |
| 136 |
moonIcon.style.display = isLight ? 'block' : 'none'; |
| 137 |
|
| 138 |
// Save preference via AJAX |
| 139 |
var xhr = new XMLHttpRequest(); |
| 140 |
xhr.open('POST', '<?php echo esc_url(admin_url('admin-ajax.php')); ?>', true); |
| 141 |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
| 142 |
xhr.send('action=ka_al_save_theme&theme=' + (isLight ? 'light' : 'dark') + '&nonce=<?php echo wp_create_nonce('ka_al_theme'); ?>'); |
| 143 |
}); |
| 144 |
})(); |
| 145 |
</script> |