inbox.php 6.9 KB

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