inbox.php 6.8 KB

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