inbox.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.messages
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_block_anonymous_users();
  9. if (api_get_setting('allow_message_tool') != 'true') {
  10. api_not_allowed(true);
  11. }
  12. $allowSocial = api_get_setting('allow_social_tool') == 'true';
  13. $allowMessage = api_get_setting('allow_message_tool') == 'true';
  14. if (isset($_GET['messages_page_nr'])) {
  15. if ($allowSocial && $allowMessage) {
  16. header('Location:inbox.php');
  17. exit;
  18. }
  19. }
  20. $nameTools = get_lang('Messages');
  21. $show_message = null;
  22. if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
  23. $info_reply = [];
  24. $info_delete = [];
  25. if (isset($_GET['form_reply'])) {
  26. //allow to insert messages
  27. $info_reply = explode(base64_encode('&%ff..x'), $_GET['form_reply']);
  28. $count_reply = count($info_reply);
  29. $button_sent = urldecode($info_reply[4]);
  30. }
  31. if (isset($_GET['form_delete'])) {
  32. //allow to delete messages
  33. $info_delete = explode(',', $_GET['form_delete']);
  34. $count_delete = (count($info_delete) - 1);
  35. }
  36. if (isset($button_sent)) {
  37. $title = urldecode($info_reply[0]);
  38. $content = str_replace("\\", "", urldecode($info_reply[1]));
  39. $user_reply = $info_reply[2];
  40. $user_email_base = str_replace(')', '(', $info_reply[5]);
  41. $user_email_prepare = explode('(', $user_email_base);
  42. if (count($user_email_prepare) == 1) {
  43. $user_email = trim($user_email_prepare[0]);
  44. } elseif (count($user_email_prepare) == 3) {
  45. $user_email = trim($user_email_prepare[1]);
  46. }
  47. $user_id_by_email = MessageManager::get_user_id_by_email($user_email);
  48. if ($info_reply[6] == 'save_form') {
  49. $user_id_by_email = $info_reply[2];
  50. }
  51. if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) {
  52. MessageManager::send_message($user_id_by_email, $title, $content);
  53. $show_message .= MessageManager::return_message($user_id_by_email, 'confirmation');
  54. $social_right_content .= MessageManager::inbox_display();
  55. exit;
  56. } elseif (is_null($user_id_by_email)) {
  57. $message_box = get_lang('ErrorSendingMessage');
  58. $show_message .= Display::return_message(api_xml_http_response_encode($message_box), 'error');
  59. $social_right_content .= MessageManager::inbox_display();
  60. exit;
  61. }
  62. } elseif (trim($info_delete[0]) == 'delete') {
  63. for ($i = 1; $i <= $count_delete; $i++) {
  64. MessageManager::delete_message_by_user_receiver(
  65. api_get_user_id(),
  66. $info_delete[$i]
  67. );
  68. }
  69. $message_box = get_lang('SelectedMessagesDeleted');
  70. $show_message .= Display::return_message(api_xml_http_response_encode($message_box));
  71. $social_right_content .= MessageManager::inbox_display();
  72. exit;
  73. }
  74. }
  75. if ($allowSocial) {
  76. $this_section = SECTION_SOCIAL;
  77. $interbreadcrumb[] = [
  78. 'url' => api_get_path(WEB_PATH).'main/social/home.php',
  79. 'name' => get_lang('SocialNetwork'),
  80. ];
  81. } else {
  82. $this_section = SECTION_MYPROFILE;
  83. $interbreadcrumb[] = [
  84. 'url' => api_get_path(WEB_PATH).'main/auth/profile.php',
  85. 'name' => get_lang('Profile'),
  86. ];
  87. }
  88. $interbreadcrumb[] = [
  89. 'url' => api_get_path(WEB_PATH).'main/messages/inbox.php',
  90. 'name' => get_lang('Messages'),
  91. ];
  92. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Inbox')];
  93. $actions = '';
  94. // Comes from normal profile
  95. if ($allowSocial == false && $allowMessage) {
  96. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
  97. Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  98. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  99. Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  100. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
  101. Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  102. }
  103. // LEFT CONTENT
  104. $social_menu_block = '';
  105. if ($allowSocial) {
  106. // Block Social Menu
  107. $social_menu_block = SocialManager::show_social_menu('messages');
  108. }
  109. // Right content
  110. $social_right_content = '';
  111. $keyword = '';
  112. if (api_get_setting('allow_social_tool') === 'true') {
  113. $actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
  114. Display::return_icon('new-message.png', get_lang('ComposeMessage'), [], 32).'</a>';
  115. $actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
  116. Display::return_icon('outbox.png', get_lang('Outbox'), [], 32).'</a>';
  117. $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/inbox.php');
  118. if ($form->validate()) {
  119. $values = $form->getSubmitValues();
  120. $keyword = $values['keyword'];
  121. }
  122. $actionsRight = $form->returnForm();
  123. $social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]);
  124. }
  125. //MAIN CONTENT
  126. if (!isset($_GET['del_msg'])) {
  127. $social_right_content .= MessageManager::inbox_display($keyword);
  128. } else {
  129. $num_msg = intval($_POST['total']);
  130. for ($i = 0; $i < $num_msg; $i++) {
  131. if ($_POST[$i]) {
  132. //the user_id was necessary to delete a message??
  133. $show_message .= MessageManager::delete_message_by_user_receiver(
  134. api_get_user_id(),
  135. $_POST['_'.$i]
  136. );
  137. }
  138. }
  139. $social_right_content .= MessageManager::inbox_display();
  140. }
  141. $tpl = new Template(null);
  142. if ($actions) {
  143. $tpl->assign('actions', Display::toolbarAction('toolbar', [$actions]));
  144. }
  145. // Block Social Avatar
  146. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
  147. if (api_get_setting('allow_social_tool') == 'true') {
  148. $tpl->assign('social_menu_block', $social_menu_block);
  149. $tpl->assign('social_right_content', $social_right_content);
  150. $social_layout = $tpl->get_template('social/inbox.tpl');
  151. $tpl->display($social_layout);
  152. } else {
  153. $content = $social_right_content;
  154. $tpl->assign('message', $show_message);
  155. $tpl->assign('content', $content);
  156. $tpl->display_one_col_template();
  157. }