inbox.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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');
  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. exit;
  19. }
  20. }
  21. if (api_get_setting('allow_message_tool') != 'true') {
  22. api_not_allowed();
  23. }
  24. $htmlHeadXtra[] = '<script>
  25. function show_icon_edit(element_html) {
  26. ident="#edit_image";
  27. $(ident).show();
  28. }
  29. function hide_icon_edit(element_html) {
  30. ident="#edit_image";
  31. $(ident).hide();
  32. }
  33. </script>';
  34. /*
  35. MAIN CODE
  36. */
  37. $nameTools = get_lang('Messages');
  38. $request = api_is_xml_http_request();
  39. $show_message = null;
  40. if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
  41. $info_reply = array();
  42. $info_delete = array();
  43. if (isset($_GET['form_reply'])) {
  44. //allow to insert messages
  45. $info_reply = explode(base64_encode('&%ff..x'), $_GET['form_reply']);
  46. $count_reply = count($info_reply);
  47. $button_sent = urldecode($info_reply[4]);
  48. }
  49. if (isset($_GET['form_delete'])) {
  50. //allow to delete messages
  51. $info_delete = explode(',', $_GET['form_delete']);
  52. $count_delete = (count($info_delete) - 1);
  53. }
  54. if (isset($button_sent)) {
  55. $title = urldecode($info_reply[0]);
  56. $content = str_replace("\\", "", urldecode($info_reply[1]));
  57. $user_reply = $info_reply[2];
  58. $user_email_base = str_replace(')', '(', $info_reply[5]);
  59. $user_email_prepare = explode('(', $user_email_base);
  60. if (count($user_email_prepare) == 1) {
  61. $user_email = trim($user_email_prepare[0]);
  62. } elseif (count($user_email_prepare) == 3) {
  63. $user_email = trim($user_email_prepare[1]);
  64. }
  65. $user_id_by_email = MessageManager::get_user_id_by_email($user_email);
  66. if ($info_reply[6] == 'save_form') {
  67. $user_id_by_email = $info_reply[2];
  68. }
  69. if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) {
  70. MessageManager::send_message($user_id_by_email, $title, $content);
  71. $show_message .= MessageManager::return_message($user_id_by_email, 'confirmation');
  72. $social_right_content .= MessageManager::inbox_display();
  73. exit;
  74. } elseif (is_null($user_id_by_email)) {
  75. $message_box = get_lang('ErrorSendingMessage');
  76. $show_message .= Display::return_message(api_xml_http_response_encode($message_box), 'error');
  77. $social_right_content .= MessageManager::inbox_display();
  78. exit;
  79. }
  80. } elseif (trim($info_delete[0]) == 'delete') {
  81. for ($i = 1; $i <= $count_delete; $i++) {
  82. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]);
  83. }
  84. $message_box = get_lang('SelectedMessagesDeleted');
  85. $show_message .= Display::return_message(api_xml_http_response_encode($message_box));
  86. $social_right_content .= MessageManager::inbox_display();
  87. exit;
  88. }
  89. }
  90. if (isset($_GET['f']) && $_GET['f'] == 'social') {
  91. $this_section = SECTION_SOCIAL;
  92. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/social/home.php', 'name' => get_lang('SocialNetwork'));
  93. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Inbox'));
  94. } else {
  95. $this_section = SECTION_MYPROFILE;
  96. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/auth/profile.php', 'name' => get_lang('Profile'));
  97. }
  98. $social_parameter = '';
  99. if (isset($_GET['f']) && $_GET['f'] == 'social' || api_get_setting('allow_social_tool') == 'true') {
  100. $social_parameter = '?f=social';
  101. } else {
  102. $actions = null;
  103. //Comes from normal profile
  104. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  105. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
  106. }
  107. if (api_get_setting('allow_message_tool') == 'true') {
  108. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  109. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  110. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  111. }
  112. }
  113. $userInfo = UserManager::get_user_info_by_id($user_id);
  114. //LEFT CONTENT
  115. if (api_get_setting('allow_social_tool') == 'true') {
  116. //Block Social Menu
  117. $social_menu_block = 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="col-md-12">';
  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="col-md-12">';
  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 necesarry 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 = new Template(null);
  147. // Block Social Avatar
  148. SocialManager::setSocialUserBlock($tpl, $user_id, 'messages');
  149. if (api_get_setting('allow_social_tool') == 'true') {
  150. $tpl->assign('social_menu_block', $social_menu_block);
  151. $tpl->assign('social_right_content', $social_right_content);
  152. $social_layout = $tpl->get_template('social/inbox.tpl');
  153. $tpl->display($social_layout);
  154. } else {
  155. $content = $social_right_content;
  156. $tpl->assign('actions', $actions);
  157. $tpl->assign('message', $show_message);
  158. $tpl->assign('content', $content);
  159. $tpl->display_one_col_template();
  160. }