activity-reports.php
3 hours ago
author-dashboard.php
5 years ago
basic.php
5 months ago
buddypress.php
5 years ago
cloud-storage.php
5 years ago
cron-jobs.php
3 hours ago
crons.php
1 year ago
frontend.php
2 years ago
privacy.php
8 months ago
profile-dashboard.php
5 years ago
social-connects.php
5 years ago
user-interface.php
4 months ago
activity-reports.php
480 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Activity Reports Settings Page |
| 4 | * |
| 5 | * @package WPDM\Admin\views\settings |
| 6 | * @since 7.0.2 |
| 7 | */ |
| 8 | |
| 9 | if (!defined('ABSPATH')) die('!'); |
| 10 | |
| 11 | // Get current settings |
| 12 | $enabled = (int) get_option('__wpdm_activity_report_enabled', 0); |
| 13 | $frequency = get_option('__wpdm_activity_report_frequency', 'weekly'); |
| 14 | $day = (int) get_option('__wpdm_activity_report_day', 1); |
| 15 | $hour = (int) get_option('__wpdm_activity_report_hour', 9); |
| 16 | $includeAdmin = (int) get_option('__wpdm_activity_report_admin', 1); |
| 17 | $additionalEmails = get_option('__wpdm_activity_report_emails', ''); |
| 18 | $sections = get_option('__wpdm_activity_report_sections', [ |
| 19 | 'download_summary', |
| 20 | 'top_packages', |
| 21 | 'user_activity', |
| 22 | 'category_breakdown', |
| 23 | ]); |
| 24 | |
| 25 | if (!is_array($sections)) { |
| 26 | $sections = ['download_summary', 'top_packages', 'user_activity']; |
| 27 | } |
| 28 | |
| 29 | // Check if Premium Packages is active |
| 30 | $hasPremiumPackages = class_exists('\\WPDMPremiumPackage') || function_exists('wpdmpp_effective_price'); |
| 31 | |
| 32 | // Available sections |
| 33 | $availableSections = [ |
| 34 | 'download_summary' => [ |
| 35 | 'label' => __('Download Summary', 'download-manager'), |
| 36 | 'description' => __('Total downloads, comparison with previous period, daily average', 'download-manager'), |
| 37 | ], |
| 38 | 'top_packages' => [ |
| 39 | 'label' => __('Top Packages', 'download-manager'), |
| 40 | 'description' => __('Most downloaded packages this period', 'download-manager'), |
| 41 | ], |
| 42 | 'trending_packages' => [ |
| 43 | 'label' => __('Trending Packages', 'download-manager'), |
| 44 | 'description' => __('Packages with biggest growth percentage', 'download-manager'), |
| 45 | ], |
| 46 | 'user_activity' => [ |
| 47 | 'label' => __('User Activity', 'download-manager'), |
| 48 | 'description' => __('New users, unique downloaders, top downloaders', 'download-manager'), |
| 49 | ], |
| 50 | 'category_breakdown' => [ |
| 51 | 'label' => __('Category Breakdown', 'download-manager'), |
| 52 | 'description' => __('Downloads per category with percentage share', 'download-manager'), |
| 53 | ], |
| 54 | 'revenue_summary' => [ |
| 55 | 'label' => __('Revenue Summary', 'download-manager'), |
| 56 | 'description' => __('Total revenue, orders, top selling products', 'download-manager'), |
| 57 | 'requires' => 'premium', |
| 58 | ], |
| 59 | 'storage_usage' => [ |
| 60 | 'label' => __('Storage Usage', 'download-manager'), |
| 61 | 'description' => __('Total storage, file count, largest packages', 'download-manager'), |
| 62 | ], |
| 63 | ]; |
| 64 | |
| 65 | // Days of week |
| 66 | $daysOfWeek = [ |
| 67 | 1 => __('Monday', 'download-manager'), |
| 68 | 2 => __('Tuesday', 'download-manager'), |
| 69 | 3 => __('Wednesday', 'download-manager'), |
| 70 | 4 => __('Thursday', 'download-manager'), |
| 71 | 5 => __('Friday', 'download-manager'), |
| 72 | 6 => __('Saturday', 'download-manager'), |
| 73 | 7 => __('Sunday', 'download-manager'), |
| 74 | ]; |
| 75 | |
| 76 | // Get admin email |
| 77 | $adminEmail = get_option('admin_email'); |
| 78 | ?> |
| 79 | |
| 80 | <style> |
| 81 | .wpdm-ar-toggle { |
| 82 | position: relative; |
| 83 | display: inline-block; |
| 84 | width: 48px; |
| 85 | height: 26px; |
| 86 | vertical-align: middle; |
| 87 | } |
| 88 | .wpdm-ar-toggle input { |
| 89 | opacity: 0; |
| 90 | width: 0; |
| 91 | height: 0; |
| 92 | } |
| 93 | .wpdm-ar-toggle-slider { |
| 94 | position: absolute; |
| 95 | cursor: pointer; |
| 96 | top: 0; |
| 97 | left: 0; |
| 98 | right: 0; |
| 99 | bottom: 0; |
| 100 | background-color: #cbd5e1; |
| 101 | border-radius: 26px; |
| 102 | transition: 0.3s; |
| 103 | } |
| 104 | .wpdm-ar-toggle-slider:before { |
| 105 | position: absolute; |
| 106 | content: ""; |
| 107 | height: 20px; |
| 108 | width: 20px; |
| 109 | left: 3px; |
| 110 | bottom: 3px; |
| 111 | background-color: white; |
| 112 | border-radius: 50%; |
| 113 | transition: 0.3s; |
| 114 | box-shadow: 0 1px 3px rgba(0,0,0,0.2); |
| 115 | } |
| 116 | .wpdm-ar-toggle input:checked + .wpdm-ar-toggle-slider { |
| 117 | background-color: #6366f1; |
| 118 | } |
| 119 | .wpdm-ar-toggle input:checked + .wpdm-ar-toggle-slider:before { |
| 120 | transform: translateX(22px); |
| 121 | } |
| 122 | .wpdm-ar-section-card { |
| 123 | display: flex; |
| 124 | align-items: flex-start; |
| 125 | padding: 12px 16px; |
| 126 | background: #f8fafc; |
| 127 | border: 1px solid #e2e8f0; |
| 128 | border-radius: 8px; |
| 129 | margin-bottom: 8px; |
| 130 | transition: all 0.15s; |
| 131 | } |
| 132 | .wpdm-ar-section-card:hover { |
| 133 | background: #f1f5f9; |
| 134 | border-color: #cbd5e1; |
| 135 | } |
| 136 | .wpdm-ar-section-card.disabled { |
| 137 | opacity: 0.5; |
| 138 | cursor: not-allowed; |
| 139 | } |
| 140 | .wpdm-ar-section-card label { |
| 141 | display: flex; |
| 142 | align-items: flex-start; |
| 143 | gap: 12px; |
| 144 | cursor: pointer; |
| 145 | flex: 1; |
| 146 | } |
| 147 | .wpdm-ar-section-card.disabled label { |
| 148 | cursor: not-allowed; |
| 149 | } |
| 150 | .wpdm-ar-section-info { |
| 151 | flex: 1; |
| 152 | } |
| 153 | .wpdm-ar-section-title { |
| 154 | font-weight: 600; |
| 155 | color: #1e293b; |
| 156 | margin: 0 0 2px 0; |
| 157 | } |
| 158 | .wpdm-ar-section-desc { |
| 159 | font-size: 12px; |
| 160 | color: #64748b; |
| 161 | margin: 0; |
| 162 | } |
| 163 | .wpdm-ar-badge { |
| 164 | display: inline-block; |
| 165 | padding: 2px 6px; |
| 166 | font-size: 10px; |
| 167 | font-weight: 600; |
| 168 | text-transform: uppercase; |
| 169 | border-radius: 4px; |
| 170 | margin-left: 8px; |
| 171 | } |
| 172 | .wpdm-ar-badge-premium { |
| 173 | background: #fef3c7; |
| 174 | color: #92400e; |
| 175 | } |
| 176 | .wpdm-ar-schedule-grid { |
| 177 | display: grid; |
| 178 | grid-template-columns: repeat(3, 1fr); |
| 179 | gap: 16px; |
| 180 | } |
| 181 | @media (max-width: 768px) { |
| 182 | .wpdm-ar-schedule-grid { |
| 183 | grid-template-columns: 1fr; |
| 184 | } |
| 185 | } |
| 186 | .wpdm-ar-test-btn { |
| 187 | display: inline-flex; |
| 188 | align-items: center; |
| 189 | gap: 8px; |
| 190 | padding: 10px 20px; |
| 191 | background: #f8fafc; |
| 192 | border: 1px solid #e2e8f0; |
| 193 | border-radius: 6px; |
| 194 | color: #475569; |
| 195 | font-size: 14px; |
| 196 | font-weight: 500; |
| 197 | cursor: pointer; |
| 198 | transition: all 0.15s; |
| 199 | } |
| 200 | .wpdm-ar-test-btn:hover { |
| 201 | background: #f1f5f9; |
| 202 | border-color: #cbd5e1; |
| 203 | color: #1e293b; |
| 204 | } |
| 205 | .wpdm-ar-test-btn:disabled { |
| 206 | opacity: 0.5; |
| 207 | cursor: not-allowed; |
| 208 | } |
| 209 | .wpdm-ar-test-btn .fa-spin { |
| 210 | animation: fa-spin 1s linear infinite; |
| 211 | } |
| 212 | @keyframes fa-spin { |
| 213 | from { transform: rotate(0deg); } |
| 214 | to { transform: rotate(360deg); } |
| 215 | } |
| 216 | .wpdm-ar-status { |
| 217 | display: inline-flex; |
| 218 | align-items: center; |
| 219 | gap: 8px; |
| 220 | padding: 8px 16px; |
| 221 | border-radius: 6px; |
| 222 | font-size: 13px; |
| 223 | margin-top: 16px; |
| 224 | } |
| 225 | .wpdm-ar-status-success { |
| 226 | background: #d1fae5; |
| 227 | color: #065f46; |
| 228 | } |
| 229 | .wpdm-ar-status-error { |
| 230 | background: #fee2e2; |
| 231 | color: #991b1b; |
| 232 | } |
| 233 | .wpdm-ar-info-box { |
| 234 | display: flex; |
| 235 | align-items: flex-start; |
| 236 | gap: 12px; |
| 237 | padding: 16px; |
| 238 | background: #eff6ff; |
| 239 | border: 1px solid #bfdbfe; |
| 240 | border-radius: 8px; |
| 241 | margin-bottom: 16px; |
| 242 | } |
| 243 | .wpdm-ar-info-box-icon { |
| 244 | color: #3b82f6; |
| 245 | font-size: 18px; |
| 246 | flex-shrink: 0; |
| 247 | } |
| 248 | .wpdm-ar-info-box-content { |
| 249 | font-size: 13px; |
| 250 | color: #1e40af; |
| 251 | line-height: 1.5; |
| 252 | } |
| 253 | </style> |
| 254 | |
| 255 | <div class="panel panel-default"> |
| 256 | <div class="panel-heading"><?php _e('Activity Reports', 'download-manager'); ?></div> |
| 257 | <div class="panel-body"> |
| 258 | <div class="wpdm-ar-info-box"> |
| 259 | <i class="fas fa-info-circle wpdm-ar-info-box-icon"></i> |
| 260 | <div class="wpdm-ar-info-box-content"> |
| 261 | <?php _e('Activity reports provide periodic summaries of your download statistics, user activity, and revenue (if applicable). Reports are sent via email to the configured recipients.', 'download-manager'); ?> |
| 262 | </div> |
| 263 | </div> |
| 264 | |
| 265 | <div class="form-group"> |
| 266 | <label style="display: flex; align-items: center; gap: 12px; cursor: pointer;"> |
| 267 | <label class="wpdm-ar-toggle"> |
| 268 | <input type="hidden" name="__wpdm_activity_report_enabled" value="0" /> |
| 269 | <input type="checkbox" name="__wpdm_activity_report_enabled" value="1" <?php checked($enabled, 1); ?> id="wpdm-ar-enable" /> |
| 270 | <span class="wpdm-ar-toggle-slider"></span> |
| 271 | </label> |
| 272 | <span style="font-weight: 600; color: #1e293b;"><?php _e('Enable Activity Reports', 'download-manager'); ?></span> |
| 273 | </label> |
| 274 | </div> |
| 275 | </div> |
| 276 | </div> |
| 277 | |
| 278 | <div id="wpdm-ar-settings" style="<?php echo !$enabled ? 'opacity: 0.5; pointer-events: none;' : ''; ?>"> |
| 279 | |
| 280 | <div class="panel panel-default"> |
| 281 | <div class="panel-heading"><?php _e('Schedule', 'download-manager'); ?></div> |
| 282 | <div class="panel-body"> |
| 283 | <div class="wpdm-ar-schedule-grid"> |
| 284 | <div class="form-group"> |
| 285 | <label><?php _e('Frequency', 'download-manager'); ?></label> |
| 286 | <select name="__wpdm_activity_report_frequency" class="form-control" id="wpdm-ar-frequency"> |
| 287 | <option value="weekly" <?php selected($frequency, 'weekly'); ?>><?php _e('Weekly', 'download-manager'); ?></option> |
| 288 | <option value="monthly" <?php selected($frequency, 'monthly'); ?>><?php _e('Monthly', 'download-manager'); ?></option> |
| 289 | </select> |
| 290 | </div> |
| 291 | |
| 292 | <div class="form-group" id="wpdm-ar-day-group"> |
| 293 | <label id="wpdm-ar-day-label"><?php _e('Send Day', 'download-manager'); ?></label> |
| 294 | <select name="__wpdm_activity_report_day" class="form-control" id="wpdm-ar-day"> |
| 295 | <?php |
| 296 | // Weekly days |
| 297 | foreach ($daysOfWeek as $dayNum => $dayName) { |
| 298 | echo '<option value="' . $dayNum . '" data-type="weekly"' . selected($day, $dayNum, false) . '>' . esc_html($dayName) . '</option>'; |
| 299 | } |
| 300 | // Monthly days |
| 301 | for ($i = 1; $i <= 28; $i++) { |
| 302 | $suffix = 'th'; |
| 303 | if ($i === 1 || $i === 21) $suffix = 'st'; |
| 304 | elseif ($i === 2 || $i === 22) $suffix = 'nd'; |
| 305 | elseif ($i === 3 || $i === 23) $suffix = 'rd'; |
| 306 | echo '<option value="' . $i . '" data-type="monthly"' . selected($day, $i, false) . '>' . $i . $suffix . '</option>'; |
| 307 | } |
| 308 | ?> |
| 309 | </select> |
| 310 | </div> |
| 311 | |
| 312 | <div class="form-group"> |
| 313 | <label><?php _e('Send Time', 'download-manager'); ?></label> |
| 314 | <select name="__wpdm_activity_report_hour" class="form-control"> |
| 315 | <?php for ($h = 0; $h < 24; $h++): ?> |
| 316 | <option value="<?php echo $h; ?>" <?php selected($hour, $h); ?>> |
| 317 | <?php echo sprintf('%02d:00', $h); ?> (<?php echo date('g:i A', strtotime(sprintf('%02d:00', $h))); ?>) |
| 318 | </option> |
| 319 | <?php endfor; ?> |
| 320 | </select> |
| 321 | </div> |
| 322 | </div> |
| 323 | </div> |
| 324 | </div> |
| 325 | |
| 326 | <div class="panel panel-default"> |
| 327 | <div class="panel-heading"><?php _e('Recipients', 'download-manager'); ?></div> |
| 328 | <div class="panel-body"> |
| 329 | <div class="form-group"> |
| 330 | <label style="display: flex; align-items: center; gap: 8px; cursor: pointer;"> |
| 331 | <input type="hidden" name="__wpdm_activity_report_admin" value="0" /> |
| 332 | <input type="checkbox" name="__wpdm_activity_report_admin" value="1" <?php checked($includeAdmin, 1); ?> /> |
| 333 | <span><?php printf(__('Site Admin (%s)', 'download-manager'), '<code>' . esc_html($adminEmail) . '</code>'); ?></span> |
| 334 | </label> |
| 335 | </div> |
| 336 | |
| 337 | <div class="form-group"> |
| 338 | <label><?php _e('Additional Email Addresses', 'download-manager'); ?></label> |
| 339 | <input type="text" name="__wpdm_activity_report_emails" class="form-control" value="<?php echo esc_attr($additionalEmails); ?>" placeholder="email1@example.com, email2@example.com" /> |
| 340 | <em class="note"><?php _e('Comma-separated list of additional email addresses to receive reports.', 'download-manager'); ?></em> |
| 341 | </div> |
| 342 | </div> |
| 343 | </div> |
| 344 | |
| 345 | <div class="panel panel-default"> |
| 346 | <div class="panel-heading"><?php _e('Report Sections', 'download-manager'); ?></div> |
| 347 | <div class="panel-body"> |
| 348 | <?php foreach ($availableSections as $key => $section): |
| 349 | $isDisabled = isset($section['requires']) && $section['requires'] === 'premium' && !$hasPremiumPackages; |
| 350 | $isChecked = in_array($key, $sections) && !$isDisabled; |
| 351 | ?> |
| 352 | <div class="wpdm-ar-section-card <?php echo $isDisabled ? 'disabled' : ''; ?>"> |
| 353 | <label> |
| 354 | <input type="checkbox" |
| 355 | name="__wpdm_activity_report_sections[]" |
| 356 | value="<?php echo esc_attr($key); ?>" |
| 357 | <?php checked($isChecked, true); ?> |
| 358 | <?php echo $isDisabled ? 'disabled' : ''; ?> /> |
| 359 | <div class="wpdm-ar-section-info"> |
| 360 | <p class="wpdm-ar-section-title"> |
| 361 | <?php echo esc_html($section['label']); ?> |
| 362 | <?php if (isset($section['requires']) && $section['requires'] === 'premium'): ?> |
| 363 | <span class="wpdm-ar-badge wpdm-ar-badge-premium"><?php _e('Premium Packages', 'download-manager'); ?></span> |
| 364 | <?php endif; ?> |
| 365 | </p> |
| 366 | <p class="wpdm-ar-section-desc"><?php echo esc_html($section['description']); ?></p> |
| 367 | </div> |
| 368 | </label> |
| 369 | </div> |
| 370 | <?php endforeach; ?> |
| 371 | |
| 372 | <?php if (!$hasPremiumPackages): ?> |
| 373 | <em class="note" style="display: block; margin-top: 12px;"> |
| 374 | <i class="fas fa-info-circle"></i> |
| 375 | <?php _e('Revenue Summary requires the Premium Packages add-on to be active.', 'download-manager'); ?> |
| 376 | </em> |
| 377 | <?php endif; ?> |
| 378 | </div> |
| 379 | </div> |
| 380 | |
| 381 | <div class="panel panel-default"> |
| 382 | <div class="panel-heading"><?php _e('Test Report', 'download-manager'); ?></div> |
| 383 | <div class="panel-body"> |
| 384 | <p style="margin: 0 0 16px 0; color: #64748b;"> |
| 385 | <?php _e('Send a test report to verify your configuration is working correctly.', 'download-manager'); ?> |
| 386 | </p> |
| 387 | |
| 388 | <div style="display: flex; align-items: center; gap: 12px;"> |
| 389 | <input type="email" id="wpdm-ar-test-email" class="form-control" style="max-width: 300px;" value="<?php echo esc_attr($adminEmail); ?>" placeholder="<?php esc_attr_e('Email address', 'download-manager'); ?>" /> |
| 390 | <button type="button" id="wpdm-ar-send-test" class="wpdm-ar-test-btn"> |
| 391 | <i class="fas fa-paper-plane"></i> |
| 392 | <?php _e('Send Test Report', 'download-manager'); ?> |
| 393 | </button> |
| 394 | </div> |
| 395 | |
| 396 | <div id="wpdm-ar-test-result"></div> |
| 397 | </div> |
| 398 | </div> |
| 399 | |
| 400 | </div> |
| 401 | |
| 402 | <script> |
| 403 | jQuery(function($) { |
| 404 | // Toggle settings visibility |
| 405 | $('#wpdm-ar-enable').on('change', function() { |
| 406 | if (this.checked) { |
| 407 | $('#wpdm-ar-settings').css({ opacity: 1, pointerEvents: 'auto' }); |
| 408 | } else { |
| 409 | $('#wpdm-ar-settings').css({ opacity: 0.5, pointerEvents: 'none' }); |
| 410 | } |
| 411 | }); |
| 412 | |
| 413 | // Update day options based on frequency |
| 414 | function updateDayOptions() { |
| 415 | var frequency = $('#wpdm-ar-frequency').val(); |
| 416 | var $daySelect = $('#wpdm-ar-day'); |
| 417 | var $dayLabel = $('#wpdm-ar-day-label'); |
| 418 | |
| 419 | $daySelect.find('option').hide(); |
| 420 | $daySelect.find('option[data-type="' + frequency + '"]').show(); |
| 421 | |
| 422 | // Select first visible option if current is hidden |
| 423 | if ($daySelect.find('option:selected').is(':hidden')) { |
| 424 | $daySelect.find('option[data-type="' + frequency + '"]:first').prop('selected', true); |
| 425 | } |
| 426 | |
| 427 | if (frequency === 'weekly') { |
| 428 | $dayLabel.text('<?php _e('Send Day', 'download-manager'); ?>'); |
| 429 | } else { |
| 430 | $dayLabel.text('<?php _e('Day of Month', 'download-manager'); ?>'); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | $('#wpdm-ar-frequency').on('change', updateDayOptions); |
| 435 | updateDayOptions(); // Initial setup |
| 436 | |
| 437 | // Send test report |
| 438 | $('#wpdm-ar-send-test').on('click', function() { |
| 439 | var $btn = $(this); |
| 440 | var $result = $('#wpdm-ar-test-result'); |
| 441 | var email = $('#wpdm-ar-test-email').val().trim(); |
| 442 | |
| 443 | if (!email) { |
| 444 | $result.html('<div class="wpdm-ar-status wpdm-ar-status-error"><i class="fas fa-exclamation-circle"></i> <?php _e('Please enter an email address.', 'download-manager'); ?></div>'); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | $btn.prop('disabled', true).html('<i class="fas fa-sync fa-spin"></i> <?php _e('Sending...', 'download-manager'); ?>'); |
| 449 | $result.html(''); |
| 450 | |
| 451 | $.post(ajaxurl, { |
| 452 | action: 'wpdm_send_test_activity_report', |
| 453 | email: email, |
| 454 | nonce: '<?php echo wp_create_nonce('wpdm_activity_report_test'); ?>' |
| 455 | }, function(response) { |
| 456 | $btn.prop('disabled', false).html('<i class="fas fa-paper-plane"></i> <?php _e('Send Test Report', 'download-manager'); ?>'); |
| 457 | |
| 458 | if (response.success) { |
| 459 | $result.html('<div class="wpdm-ar-status wpdm-ar-status-success"><i class="fas fa-check-circle"></i> ' + response.data.message + '</div>'); |
| 460 | } else { |
| 461 | $result.html('<div class="wpdm-ar-status wpdm-ar-status-error"><i class="fas fa-exclamation-circle"></i> ' + (response.data ? response.data.message : '<?php _e('Failed to send test report.', 'download-manager'); ?>') + '</div>'); |
| 462 | } |
| 463 | }).fail(function() { |
| 464 | $btn.prop('disabled', false).html('<i class="fas fa-paper-plane"></i> <?php _e('Send Test Report', 'download-manager'); ?>'); |
| 465 | $result.html('<div class="wpdm-ar-status wpdm-ar-status-error"><i class="fas fa-exclamation-circle"></i> <?php _e('Request failed. Please try again.', 'download-manager'); ?></div>'); |
| 466 | }); |
| 467 | }); |
| 468 | |
| 469 | // After settings save, reschedule job |
| 470 | WPDM.addAction("wpdm_save_settings", function(page, data) { |
| 471 | if (page === 'activity-reports') { |
| 472 | $.post(ajaxurl, { |
| 473 | action: 'wpdm_reschedule_activity_report', |
| 474 | nonce: '<?php echo wp_create_nonce('wpdm_reschedule_activity_report'); ?>' |
| 475 | }); |
| 476 | } |
| 477 | }); |
| 478 | }); |
| 479 | </script> |
| 480 |