AdminDashboard.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class AdminDashboard implements IDashboard {
  3. public function display($urlTree) {
  4. $dashboardPage = isset($urlTree[1]) ? $urlTree[1] : "home";
  5. switch($dashboardPage) {
  6. case "accounts":
  7. return $this->accounts();
  8. case "users":
  9. return $this->users();
  10. case "data":
  11. return $this->data();
  12. case "home":
  13. case "":
  14. return $this->home();
  15. default:
  16. header('Location: /dashboard/');
  17. }
  18. }
  19. public function home() {
  20. $data = array();
  21. $data['sectionName'] = "";
  22. $data['displayName'] = $_SESSION['display_name'];
  23. $log = new SecurityLogger();
  24. $data['activity_log'] = $log->read();
  25. $data['last_seven_days'] = array($this->getDayAgo(6), $this->getDayAgo(5), $this->getDayAgo(4), $this->getDayAgo(3), $this->getDayAgo(2), $this->getDayAgo(1), $this->getDayAgo(0));
  26. $data['user_logins'] = array(2, 3, 5, 4, 2, 4, 8);
  27. $data['admin_logins'] = array(2, 3, 5, 4, 2, 4, 8);
  28. $data['client_logins'] = array(8, 4, 2, 4, 4, 3, 2);
  29. $data['failed_logins'] = array(0, 8, 4, 8, 7, 6, 4);
  30. return (new View())->render("admin/dashboard.php", $data);
  31. }
  32. private function getDayAgo($daysAgo) {
  33. return date('l', strtotime('-'.$daysAgo.' days'));
  34. }
  35. public function accounts() {
  36. $database = SqliteDatabase::getSingleton();
  37. $accounts = $database->queryArray("SELECT rowid AS client_id, * FROM accounts;");
  38. $data = array();
  39. $data['sectionName'] = "Accounts";
  40. $data['displayName'] = $_SESSION['display_name'];
  41. $data['accounts'] = $accounts;
  42. return (new View())->render("admin/accounts.php", $data);
  43. }
  44. public function users() {
  45. $database = SqliteDatabase::getSingleton();
  46. $users = $database->queryArray("SELECT rowid AS user_id, display_name, username FROM users;");
  47. foreach($users as $index => $user) {
  48. $domains = $database->queryArray("SELECT subdomain, display_name FROM user_accounts JOIN accounts ON accounts.rowid = user_accounts.account_id WHERE user_id = " . $user['user_id']. ";");
  49. foreach($domains as $domain) {
  50. $users[$index]['domains'][] = $domain['subdomain'];
  51. }
  52. }
  53. $data = array();
  54. $data['sectionName'] = "Users";
  55. $data['displayName'] = $_SESSION['display_name'];
  56. $data['users'] = $users;
  57. return (new View())->render("admin/users.php", $data);
  58. }
  59. public function data() {
  60. //http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html
  61. $database = SqliteDatabase::getSingleton();
  62. $projects = $database->queryArray("SELECT rowid AS project_id, * FROM projects;");
  63. foreach($projects as $index => $project) {
  64. $accounts = $database->queryArray("SELECT display_name FROM account_projects JOIN accounts ON accounts.rowid = account_projects.account_id WHERE project_id = " . $project['project_id']. ";");
  65. foreach($accounts as $account) {
  66. $projects[$index]['clients'][] = $account['display_name'];
  67. }
  68. }
  69. $data = array();
  70. $data['sectionName'] = "Data";
  71. $data['displayName'] = $_SESSION['display_name'];
  72. $data['projects'] = $projects;
  73. return (new View())->render("admin/data.php", $data);
  74. }
  75. }