inbox.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 '../messages/message.class.php';
  31. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  32. api_block_anonymous_users();
  33. if (isset($_GET['messages_page_nr'])) {
  34. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  35. header('Location:../social/index.php?pager="'.Security::remove_XSS($_GET['messages_page_nr']).'"&remote=2#remote-tab-2');
  36. }
  37. }
  38. if (api_get_setting('allow_message_tool')!='true'){
  39. api_not_allowed();
  40. }
  41. $htmlHeadXtra[]='<script language="javascript">
  42. <!--
  43. function enviar(miforma)
  44. {
  45. if(confirm("'.get_lang("SureYouWantToDeleteSelectedMessages").'"))
  46. miforma.submit();
  47. }
  48. function select_all(formita)
  49. {
  50. for (i=0;i<formita.elements.length;i++)
  51. {
  52. if(formita.elements[i].type == "checkbox")
  53. formita.elements[i].checked=1
  54. }
  55. }
  56. function deselect_all(formita)
  57. {
  58. for (i=0;i<formita.elements.length;i++)
  59. {
  60. if(formita.elements[i].type == "checkbox")
  61. formita.elements[i].checked=0
  62. }
  63. }
  64. //-->
  65. </script>';
  66. /*
  67. ==============================================================================
  68. MAIN CODE
  69. ==============================================================================
  70. */
  71. $nameTools = get_lang('Messages');
  72. $request=api_is_xml_http_request();
  73. if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) {
  74. /***********************************************/
  75. $info_reply=array();
  76. $info_delete=array();
  77. /***********************************************/
  78. if ( isset($_GET['form_reply']) ) {
  79. //allow to insert messages
  80. $info_reply=explode(base64_encode('&%ff..x'),$_GET['form_reply']);
  81. $count_reply=count($info_reply);
  82. $button_sent=urldecode($info_reply[4]);
  83. }
  84. /***********************************************/
  85. if ( isset($_GET['form_delete']) ) {
  86. //allow to delete messages
  87. $info_delete=explode(',',$_GET['form_delete']);
  88. $count_delete=(count($info_delete)-1);
  89. }
  90. /***********************************************/
  91. if ( isset($button_sent) ) {
  92. $title = api_convert_encoding(urldecode($info_reply[0]),'UTF-8',$charset);
  93. $content = api_convert_encoding(str_replace("\\","",urldecode($info_reply[1])),'UTF-8',$charset);
  94. $title = Security::remove_XSS($title);
  95. $content = Security::remove_XSS($content,COURSEMANAGERLOWSECURITY);
  96. $user_reply= $info_reply[2];
  97. $user_email_base=str_replace(')','(',$info_reply[5]);
  98. $user_email_prepare=explode('(',$user_email_base);
  99. if (count($user_email_prepare)==1) {
  100. $user_email=trim($user_email_prepare[0]);
  101. } elseif (count($user_email_prepare)==3) {
  102. $user_email=trim($user_email_prepare[1]);
  103. }
  104. $user_id_by_email=MessageManager::get_user_id_by_email($user_email);
  105. if ($info_reply[6]=='save_form') {
  106. $user_id_by_email=$info_reply[2];
  107. }
  108. if ( isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) >0) {
  109. MessageManager::send_message($user_id_by_email, $title, $content);
  110. MessageManager::display_success_message($user_id_by_email);
  111. inbox_display();
  112. exit;
  113. } elseif (is_null($user_id_by_email)) {
  114. $message_box=get_lang('ErrorSendingMessage');
  115. Display::display_error_message(api_xml_http_response_encode($message_box),false);
  116. inbox_display();
  117. exit;
  118. }
  119. } elseif (trim($info_delete[0])=='delete' ) {
  120. for ($i=1;$i<=$count_delete;$i++) {
  121. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $info_delete[$i]);
  122. }
  123. $message_box=get_lang('SelectedMessagesDeleted');
  124. Display::display_normal_message(api_xml_http_response_encode($message_box),false);
  125. inbox_display();
  126. exit;
  127. }
  128. }
  129. if ($request===false) {
  130. $interbreadcrumb[]= array (
  131. 'url' => '#',
  132. 'name' => get_lang('Messages')
  133. );
  134. $interbreadcrumb[]= array (
  135. 'url' => 'outbox.php',
  136. 'name' => get_lang('Outbox')
  137. );
  138. $interbreadcrumb[]= array (
  139. 'url' => 'inbox.php',
  140. 'name' => get_lang('Inbox')
  141. );
  142. Display::display_header('');
  143. $link_ref="new_message.php";
  144. } else {
  145. $link_ref="../messages/new_message.php?rs=1";
  146. }
  147. $table_message = Database::get_main_table(TABLE_MESSAGE);
  148. /*echo '<div id="div_content_messages">&nbsp;&nbsp;';
  149. //api_display_tool_title(api_xml_http_response_encode(get_lang('Inbox')));
  150. echo '<div class=actions>';
  151. echo '<a onclick="compose_and_show_message(\'show\',\'1\')" href="javascript:void(0)">'.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 '</div>';
  153. echo '</div>';*/
  154. if (!isset($_GET['del_msg'])) {
  155. inbox_display();
  156. } else {
  157. $num_msg = $_POST['total'];
  158. for ($i=0;$i<$num_msg;$i++) {
  159. if($_POST[$i]) {
  160. //the user_id was necesarry to delete a message??
  161. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_POST['_'.$i]);
  162. }
  163. }
  164. inbox_display();
  165. }
  166. /*
  167. ==============================================================================
  168. FOOTER
  169. ==============================================================================
  170. */
  171. if ($request===false) {
  172. Display::display_footer();
  173. }
  174. ?>