inbox.php 6.4 KB

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