inbox.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com>
  7. Copyright (c) Facultad de Matematicas, UADY (México)
  8. Copyright (c) Evie, Free University of Brussels (Belgium)
  9. Copyright (c) 2009 Isaac Flores Paz <isaac.flores@dokeos.com>
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /*
  22. ==============================================================================
  23. INIT SECTION
  24. ==============================================================================
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = array('registration','messages','userInfo','admin','index');
  28. $cidReset=true;
  29. require_once '../inc/global.inc.php';
  30. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  31. api_block_anonymous_users();
  32. if (isset($_GET['messages_page_nr'])) {
  33. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  34. header('Location:../social/index.php?pager="'.Security::remove_XSS($_GET['messages_page_nr']).'"&remote=2#remote-tab-2');
  35. }
  36. }
  37. if (api_get_setting('allow_message_tool')!='true'){
  38. api_not_allowed();
  39. }
  40. $htmlHeadXtra[]='<script language="javascript">
  41. <!--
  42. function enviar(miforma)
  43. {
  44. if(confirm("'.get_lang("SureYouWantToDeleteSelectedMessages").'"))
  45. miforma.submit();
  46. }
  47. function select_all(formita)
  48. {
  49. for (i=0;i<formita.elements.length;i++)
  50. {
  51. if(formita.elements[i].type == "checkbox")
  52. formita.elements[i].checked=1
  53. }
  54. }
  55. function deselect_all(formita)
  56. {
  57. for (i=0;i<formita.elements.length;i++)
  58. {
  59. if(formita.elements[i].type == "checkbox")
  60. formita.elements[i].checked=0
  61. }
  62. }
  63. //-->
  64. </script>';
  65. /*
  66. ==============================================================================
  67. MAIN CODE
  68. ==============================================================================
  69. */
  70. $nameTools = get_lang('Messages');
  71. $request=api_is_xml_http_request();
  72. if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
  73. /***********************************************/
  74. $info_reply=array();
  75. $info_delete=array();
  76. /***********************************************/
  77. if ( isset($_GET['form_reply']) ) {
  78. //allow to insert messages
  79. $info_reply=explode(base64_encode('&%ff..x'),$_GET['form_reply']);
  80. $count_reply=count($info_reply);
  81. $button_sent=urldecode($info_reply[4]);
  82. }
  83. /***********************************************/
  84. if ( isset($_GET['form_delete']) ) {
  85. //allow to delete messages
  86. $info_delete=explode(',',$_GET['form_delete']);
  87. $count_delete=(count($info_delete)-1);
  88. }
  89. /***********************************************/
  90. if ( isset($button_sent) ) {
  91. $title = api_convert_encoding(urldecode($info_reply[0]),'UTF-8',$charset);
  92. $content = api_convert_encoding(str_replace("\\","",urldecode($info_reply[1])),'UTF-8',$charset);
  93. $title = Security::remove_XSS($title);
  94. $content = Security::remove_XSS($content,COURSEMANAGERLOWSECURITY);
  95. $user_reply= $info_reply[2];
  96. $user_email_base=str_replace(')','(',$info_reply[5]);
  97. $user_email_prepare=explode('(',$user_email_base);
  98. if (count($user_email_prepare)==1) {
  99. $user_email=trim($user_email_prepare[0]);
  100. } elseif (count($user_email_prepare)==3) {
  101. $user_email=trim($user_email_prepare[1]);
  102. }
  103. $user_id_by_email=MessageManager::get_user_id_by_email($user_email);
  104. if ($info_reply[6]=='save_form') {
  105. $user_id_by_email=$info_reply[2];
  106. }
  107. if ( isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) >0) {
  108. MessageManager::send_message($user_id_by_email, $title, $content);
  109. MessageManager::display_success_message($user_id_by_email);
  110. inbox_display();
  111. exit;
  112. } elseif (is_null($user_id_by_email)) {
  113. $message_box=get_lang('ErrorSendingMessage');
  114. Display::display_error_message(api_xml_http_response_encode($message_box),false);
  115. inbox_display();
  116. exit;
  117. }
  118. } elseif (trim($info_delete[0])=='delete' ) {
  119. for ($i=1;$i<=$count_delete;$i++) {
  120. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]);
  121. }
  122. $message_box=get_lang('SelectedMessagesDeleted');
  123. Display::display_normal_message(api_xml_http_response_encode($message_box),false);
  124. inbox_display();
  125. exit;
  126. }
  127. }
  128. $link_ref="new_message.php";
  129. $table_message = Database::get_main_table(TABLE_MESSAGE);
  130. //api_display_tool_title(api_xml_http_response_encode(get_lang('Inbox')));
  131. if ($_GET['f']=='social') {
  132. $this_section = SECTION_SOCIAL;
  133. $interbreadcrumb[]= array ('url' => '#','name' => get_lang('Profile'));
  134. $interbreadcrumb[]= array ('url' => 'outbox.php','name' => get_lang('Inbox'));
  135. } else {
  136. $this_section = SECTION_MYPROFILE;
  137. $interbreadcrumb[]= array ('url' => '#','name' => get_lang('Profile'));
  138. $interbreadcrumb[]= array ('url' => 'outbox.php','name' => get_lang('Inbox'));
  139. }
  140. Display::display_header('');
  141. if ($_GET['f']=='social') {
  142. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  143. SocialManager::show_social_menu();
  144. echo '<div class="actions-title">';
  145. echo get_lang('Messages');
  146. echo '</div>';
  147. } else {
  148. //comes from normal profile
  149. echo '<div class=actions>';
  150. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon('inbox.png',api_xml_http_response_encode(get_lang('Inbox'))).api_xml_http_response_encode(get_lang('Inbox')).'</a>';
  151. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).api_xml_http_response_encode(get_lang('ComposeMessage')).'</a>';
  152. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.Display::return_icon('outbox.png',api_xml_http_response_encode(get_lang('Outbox'))).api_xml_http_response_encode(get_lang('Outbox')).'</a>';
  153. echo '</div>';
  154. }
  155. if (!isset($_GET['del_msg'])) {
  156. inbox_display();
  157. } else {
  158. $num_msg = intval($_POST['total']);
  159. for ($i=0;$i<$num_msg;$i++) {
  160. if($_POST[$i]) {
  161. //the user_id was necesarry to delete a message??
  162. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_POST['_'.$i]);
  163. }
  164. }
  165. inbox_display();
  166. }
  167. /*
  168. ==============================================================================
  169. FOOTER
  170. ==============================================================================
  171. */
  172. if ($request===false) {
  173. Display::display_footer();
  174. }
  175. ?>