statistics.ajax.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once __DIR__.'/../global.inc.php';
  7. api_protect_admin_script();
  8. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  9. switch ($action) {
  10. case 'recentlogins':
  11. header('Content-type: application/json');
  12. $list = [];
  13. $all = Statistics::getRecentLoginStats();
  14. $distinct = Statistics::getRecentLoginStats(true);
  15. foreach ($all as $tick => $tock) {
  16. $list['labels'][] = $tick;
  17. }
  18. $list['datasets'][0]['label'] = get_lang('Logins');
  19. $list['datasets'][0]['fillColor'] = "rgba(151,187,205,0.2)";
  20. $list['datasets'][0]['strokeColor'] = "rgba(151,187,205,1)";
  21. $list['datasets'][0]['pointColor'] = "rgba(151,187,205,1)";
  22. $list['datasets'][0]['pointStrokeColor'] = "#fff";
  23. $list['datasets'][0]['pointHighlightFill'] = "#fff";
  24. $list['datasets'][0]['pointHighlightStroke'] = "rgba(151,187,205,1)";
  25. foreach ($all as $tick => $tock) {
  26. $list['datasets'][0]['data'][] = $tock;
  27. }
  28. $list['datasets'][1]['label'] = get_lang('DistinctUsersLogins');
  29. $list['datasets'][1]['fillColor'] = "rgba(0,204,0,0.2)";
  30. $list['datasets'][1]['strokeColor'] = "rgba(0,204,0,1)";
  31. $list['datasets'][1]['pointColor'] = "rgba(0,204,0,1)";
  32. $list['datasets'][1]['pointStrokeColor'] = "#fff";
  33. $list['datasets'][1]['pointHighlightFill'] = "#fff";
  34. $list['datasets'][1]['pointHighlightStroke'] = "rgba(0,204,0,1)";
  35. foreach ($distinct as $tick => $tock) {
  36. $list['datasets'][1]['data'][] = $tock;
  37. }
  38. echo json_encode($list);
  39. break;
  40. }