inbox.php 6.8 KB

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