messages.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $allow = api_get_configuration_value('allow_user_message_tracking');
  5. if (!$allow) {
  6. api_not_allowed(true);
  7. }
  8. $allowUser = api_is_platform_admin() || api_is_drh();
  9. if (!$allowUser) {
  10. api_not_allowed(true);
  11. }
  12. $fromUserId = isset($_GET['from_user']) ? (int) $_GET['from_user'] : 0;
  13. $toUserId = isset($_GET['to_user']) ? (int) $_GET['to_user'] : 0;
  14. if (empty($fromUserId) || empty($toUserId)) {
  15. api_not_allowed(true);
  16. }
  17. if (api_is_drh()) {
  18. $isFollowed = UserManager::is_user_followed_by_drh($fromUserId, api_get_user_id());
  19. if (api_drh_can_access_all_session_content()) {
  20. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  21. 'drh_all',
  22. api_get_user_id(),
  23. false,
  24. 0, //$from,
  25. null, //$limit,
  26. null, //$column,
  27. 'desc', //$direction,
  28. null, //$keyword,
  29. null, //$active,
  30. null, //$lastConnectionDate,
  31. null,
  32. null,
  33. STUDENT
  34. );
  35. if (empty($students)) {
  36. api_not_allowed(true);
  37. }
  38. $userIdList = [];
  39. foreach ($students as $student) {
  40. $userIdList[] = $student['user_id'];
  41. }
  42. if (!in_array($fromUserId, $userIdList)) {
  43. api_not_allowed(true);
  44. }
  45. } else {
  46. if (!$isFollowed) {
  47. api_not_allowed(true);
  48. }
  49. }
  50. }
  51. $usersData[$toUserId] = api_get_user_info($toUserId);
  52. $usersData[$fromUserId] = api_get_user_info($fromUserId);
  53. $messages = MessageManager::getAllMessagesBetweenStudents($toUserId, $fromUserId);
  54. $content = Display::page_subheader2(sprintf(
  55. get_lang('MessagesExchangeBetweenXAndY'),
  56. $usersData[$toUserId]['complete_name'],
  57. $usersData[$fromUserId]['complete_name']
  58. ));
  59. $interbreadcrumb[] = [
  60. 'url' => api_get_path(WEB_CODE_PATH).'mySpace/student.php',
  61. 'name' => get_lang('MyStudents'),
  62. ];
  63. $interbreadcrumb[] = [
  64. 'url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$fromUserId,
  65. 'name' => get_lang('StudentDetails'),
  66. ];
  67. $uniqueMessageList = [];
  68. foreach ($messages as $message) {
  69. $message['title'].
  70. $subText = get_lang('From').': '.$usersData[$message['user_sender_id']]['complete_name'];
  71. $title = empty($message['title']) ? get_lang('Untitled') : $message['title'];
  72. $title = $title.' - '.$subText.'<span class="pull-right">'.Display::dateToStringAgoAndLongDate($message['send_date']).'</span>';
  73. $messageId = $message['id'];
  74. $hash = sha1($message['title'].$message['content'].$message['send_date']);
  75. if (in_array($hash, $uniqueMessageList)) {
  76. continue;
  77. }
  78. $content .= Display::panelCollapse(
  79. $title,
  80. $message['content'].'<br />'.Display::dateToStringAgoAndLongDate($message['send_date']),
  81. 'message-'.$message['id'],
  82. null,
  83. 'message-'.$message['id'],
  84. 'collapse-'.$message['id'],
  85. false
  86. );
  87. $uniqueMessageList[] = $hash;
  88. }
  89. $template = new Template(get_lang('MessageTracking'));
  90. $template->assign('content', $content);
  91. $template->display_one_col_template();