PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/php/main/messages/inbox.php

https://bitbucket.org/frchico/chamilo_openshift
PHP | 180 lines | 141 code | 21 blank | 18 comment | 53 complexity | d98aac8c6e734cd471740c8cf8843f06 MD5 | raw file
  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. require_once '../inc/global.inc.php';
  13. api_block_anonymous_users();
  14. if (isset($_GET['messages_page_nr'])) {
  15. $social_link = '';
  16. if ($_REQUEST['f'] == 'social') {
  17. $social_link = '?f=social';
  18. }
  19. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  20. header('Location:inbox.php'.$social_link);
  21. }
  22. }
  23. if (api_get_setting('allow_message_tool') != 'true') {
  24. api_not_allowed();
  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. /*
  37. MAIN CODE
  38. */
  39. $nameTools = get_lang('Messages');
  40. $request = api_is_xml_http_request();
  41. if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
  42. $info_reply = array();
  43. $info_delete = array();
  44. if (isset($_GET['form_reply'])) {
  45. //allow to insert messages
  46. $info_reply = explode(base64_encode('&%ff..x'), $_GET['form_reply']);
  47. $count_reply = count($info_reply);
  48. $button_sent = urldecode($info_reply[4]);
  49. }
  50. if (isset($_GET['form_delete'])) {
  51. //allow to delete messages
  52. $info_delete = explode(',', $_GET['form_delete']);
  53. $count_delete = (count($info_delete) - 1);
  54. }
  55. if (isset($button_sent)) {
  56. $title = urldecode($info_reply[0]);
  57. $content = str_replace("\\", "", urldecode($info_reply[1]));
  58. $user_reply = $info_reply[2];
  59. $user_email_base = str_replace(')', '(', $info_reply[5]);
  60. $user_email_prepare = explode('(', $user_email_base);
  61. if (count($user_email_prepare) == 1) {
  62. $user_email = trim($user_email_prepare[0]);
  63. } elseif (count($user_email_prepare) == 3) {
  64. $user_email = trim($user_email_prepare[1]);
  65. }
  66. $user_id_by_email = MessageManager::get_user_id_by_email($user_email);
  67. if ($info_reply[6] == 'save_form') {
  68. $user_id_by_email = $info_reply[2];
  69. }
  70. if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) {
  71. MessageManager::send_message($user_id_by_email, $title, $content);
  72. $show_message .= MessageManager::return_message($user_id_by_email, 'confirmation');
  73. $social_right_content .= MessageManager::inbox_display();
  74. exit;
  75. } elseif (is_null($user_id_by_email)) {
  76. $message_box = get_lang('ErrorSendingMessage');
  77. $show_message .= 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. $show_message .= 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('url' => api_get_path(WEB_PATH).'main/auth/profile.php', 'name' => get_lang('Profile'));
  98. }
  99. $social_parameter = '';
  100. if (isset($_GET['f']) && $_GET['f'] == 'social' || api_get_setting('allow_social_tool') == 'true') {
  101. $social_parameter = '?f=social';
  102. } else {
  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. //LEFT CONTENT
  114. if (api_get_setting('allow_social_tool') == 'true') {
  115. $social_left_content = 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_left_content', $social_left_content);
  147. $tpl->assign('social_right_content', $social_right_content);
  148. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  149. $tpl->display($social_layout);
  150. } else {
  151. $content = $social_right_content;
  152. $tpl->assign('actions', $actions);
  153. $tpl->assign('message', $show_message);
  154. $tpl->assign('content', $content);
  155. $tpl->display_one_col_template();
  156. }