index.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // Main include
  3. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  4. function formatNotificationTimestamps(&$note) {
  5. $dateTime = DateTime::createFromFormat("Y-m-d H:i:s", $note["DATE"] . " " . $note["TIME"]);
  6. $note["TIMESTAMP_TEXT"] = $dateTime->format("d M Y, H:i");
  7. $note["TIMESTAMP_ISO"] = $dateTime->format(DateTime::ATOM); // ISO 8601 format
  8. $note["TIMESTAMP_TITLE"] = $dateTime->format("d F Y, H:i:s");
  9. }
  10. if ($_REQUEST["ajax"] == 1 && $_REQUEST["token"] == $_SESSION["token"]) {
  11. // Data
  12. exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
  13. $data = json_decode(implode("", $output), true);
  14. foreach ($data as $key => &$note) {
  15. formatNotificationTimestamps($note);
  16. }
  17. unset($note);
  18. function sort_priority_id($element1, $element2) {
  19. return $element2["PRIORITY"] <=> $element1["PRIORITY"];
  20. }
  21. $data = array_reverse($data, true);
  22. usort($data, "sort_priority_id");
  23. foreach ($data as $key => $note) {
  24. $note["ID"] = $key;
  25. $data[$key] = $note;
  26. }
  27. echo json_encode($data);
  28. exit();
  29. }
  30. $TAB = "NOTIFICATIONS";
  31. // Data
  32. exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
  33. $data = json_decode(implode("", $output), true);
  34. $data = array_reverse($data, true);
  35. // Render page
  36. render_page($user, $TAB, "list_notifications");
  37. // Back uri
  38. $_SESSION["back"] = $_SERVER["REQUEST_URI"];