inbox.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * @package chamilo.messages
  6. */
  7. $cidReset = true;
  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('social.allow_social_tool') == 'true' &&
  15. api_get_setting('message.allow_message_tool') == 'true'
  16. ) {
  17. header('Location:inbox.php'.$social_link);
  18. exit;
  19. }
  20. }
  21. if (api_get_setting('message.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. 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. Display::addFlash(
  71. MessageManager::return_message($user_id_by_email, 'confirmation')
  72. );
  73. $social_right_content .= MessageManager::inbox_display();
  74. exit;
  75. } elseif (is_null($user_id_by_email)) {
  76. $message_box = get_lang('ErrorSendingMessage');
  77. Display::return_message(api_xml_http_response_encode($message_box), 'error');
  78. $social_right_content .= MessageManager::inbox_display();
  79. exit;
  80. }
  81. } elseif (trim($info_delete[0]) == 'delete') {
  82. for ($i = 1; $i <= $count_delete; $i++) {
  83. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]);
  84. }
  85. $message_box = get_lang('SelectedMessagesDeleted');
  86. Display::return_message(api_xml_http_response_encode($message_box));
  87. $social_right_content .= MessageManager::inbox_display();
  88. exit;
  89. }
  90. }
  91. if (isset($_GET['f']) && $_GET['f'] == 'social') {
  92. $this_section = SECTION_SOCIAL;
  93. $interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'main/social/home.php', 'name' => get_lang('SocialNetwork'));
  94. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Inbox'));
  95. } else {
  96. $this_section = SECTION_MYPROFILE;
  97. $interbreadcrumb[] = array(
  98. 'url' => Container::getRouter()->generate('fos_user_profile_edit'),
  99. 'name' => get_lang('Profile'),
  100. );
  101. }
  102. $social_parameter = '';
  103. if (isset($_GET['f']) && $_GET['f'] == 'social' && api_get_setting('social.allow_social_tool') == 'true') {
  104. $social_parameter = '?f=social';
  105. } else {
  106. $actions = null;
  107. //Comes from normal profile
  108. if (api_get_setting('social.allow_social_tool') == 'true' &&
  109. api_get_setting('message.allow_message_tool') == 'true'
  110. ) {
  111. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.
  112. Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
  113. }
  114. if (api_get_setting('message.allow_message_tool') == 'true') {
  115. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
  116. Display::return_icon('message_new.png', get_lang('ComposeMessage')).'</a>';
  117. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  118. Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
  119. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
  120. Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
  121. }
  122. }
  123. //LEFT CONTENT
  124. if (api_get_setting('social.allow_social_tool') == 'true') {
  125. //Block Social Menu
  126. $social_menu_block = SocialManager::show_social_menu('messages');
  127. }
  128. //Right content
  129. $social_right_content = null;
  130. $keyword = '';
  131. if (api_get_setting('social.allow_social_tool') == 'true') {
  132. $actionsLeft = '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php?f=social">'.
  133. Display::return_icon('new-message.png', get_lang('ComposeMessage'), array(), 32).'</a>';
  134. $actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php?f=social">'.
  135. Display::return_icon('outbox.png', get_lang('Outbox'), array(), 32).'</a>';
  136. $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/inbox.php');
  137. if ($form->validate()) {
  138. $values = $form->getSubmitValues();
  139. $keyword = $values['keyword'];
  140. }
  141. $actionsRight = $form->returnForm();
  142. $social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]);
  143. }
  144. //MAIN CONTENT
  145. if (!isset($_GET['del_msg'])) {
  146. $social_right_content .= MessageManager::inbox_display();
  147. } else {
  148. $num_msg = intval($_POST['total']);
  149. for ($i = 0; $i < $num_msg; $i++) {
  150. if ($_POST[$i]) {
  151. //the user_id was necesarry to delete a message??
  152. Display::addFlash(
  153. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_POST['_'.$i])
  154. );
  155. }
  156. }
  157. $social_right_content .= MessageManager::inbox_display();
  158. }
  159. if (api_get_setting('social.allow_social_tool') == 'true') {
  160. $social_right_content .= '</div>';
  161. }
  162. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  163. // Block Social Avatar
  164. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
  165. if (api_get_setting('social.allow_social_tool') == 'true') {
  166. $tpl->addGlobal('social_menu_block', $social_menu_block);
  167. $tpl->addGlobal('social_right_content', $social_right_content);
  168. echo $tpl->render('@template_style/social/inbox.html.twig');
  169. } else {
  170. $content = $social_right_content;
  171. echo $actions;
  172. echo $content;
  173. }