inbox.php 6.7 KB

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