inbox.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/messages/inbox.php', 'name' => get_lang('Messages'));
  94. $social_parameter = '';
  95. if (isset($_GET['f']) && $_GET['f'] == 'social' || api_get_setting('allow_social_tool') == 'true') {
  96. $social_parameter = '?f=social';
  97. } else {
  98. //Comes from normal profile
  99. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  100. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
  101. }
  102. if (api_get_setting('allow_message_tool') == 'true') {
  103. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  104. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  105. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  106. }
  107. }
  108. //LEFT CONTENT
  109. if (api_get_setting('allow_social_tool') == 'true') {
  110. $social_left_content = SocialManager::show_social_menu('messages');
  111. }
  112. //Right content
  113. $social_right_content = null;
  114. if (api_get_setting('allow_social_tool') == 'true') {
  115. $social_right_content .= '<div class="span9">';
  116. $social_right_content .= '<div class="actions">';
  117. $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>';
  118. $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>';
  119. $social_right_content .= '</div>';
  120. $social_right_content .= '</div>';
  121. $social_right_content .= '<div class="span9">';
  122. }
  123. //MAIN CONTENT
  124. if (!isset($_GET['del_msg'])) {
  125. $social_right_content .= MessageManager::inbox_display();
  126. } else {
  127. $num_msg = intval($_POST['total']);
  128. for ($i = 0; $i < $num_msg; $i++) {
  129. if ($_POST[$i]) {
  130. //the user_id was necessary to delete a message??
  131. $show_message .= MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_POST['_'.$i]);
  132. }
  133. }
  134. $social_right_content .= MessageManager::inbox_display();
  135. }
  136. if (api_get_setting('allow_social_tool') == 'true') {
  137. $social_right_content .= '</div>';
  138. }
  139. $tpl = $app['template'];
  140. $content = $social_right_content;
  141. $tpl->assign('actions', $actions);
  142. $tpl->assign('message', $show_message);
  143. $tpl->assign('content', $content);
  144. $tpl->display_one_col_template();