message.lib.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) Julio Montoya <gugli100@gmail.com>
  7. Copyright (c) Isaac Flores <florespaz_isaac@hotmail.com>
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. require_once api_get_path(LIBRARY_PATH).'online.inc.php';
  20. require_once api_get_path(SYS_CODE_PATH).'messages/message.class.php';
  21. function inbox_display() {
  22. global $charset;
  23. echo '<div id="div_content_messages">&nbsp;&nbsp;';
  24. //api_display_tool_title(api_xml_http_response_encode(get_lang('Inbox')));
  25. echo '<div class=actions>';
  26. 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>';
  27. echo '<a class="refresh" href="javascript:window.location.reload()">'.api_convert_encoding(get_lang('Refresh'),'UTF-8',$charset).'</a>';
  28. echo '</div>';
  29. echo '</div>';
  30. $charset = api_get_setting('platform_charset');
  31. $table_message = Database::get_main_table(TABLE_MESSAGE);
  32. $request=api_is_xml_http_request();
  33. if ($_SESSION['social_exist']===true) {
  34. $redirect="#remote-tab-2";
  35. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  36. $success= get_lang('SelectedMessagesDeleted');
  37. } else {
  38. $success= get_lang('SelectedMessagesDeleted');
  39. }
  40. } else {
  41. $success= get_lang('SelectedMessagesDeleted');
  42. }
  43. if (isset ($_REQUEST['action'])) {
  44. switch ($_REQUEST['action']) {
  45. case 'delete' :
  46. $number_of_selected_messages = count($_POST['id']);
  47. foreach ($_POST['id'] as $index => $message_id) {
  48. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id);
  49. }
  50. Display::display_normal_message(api_xml_http_response_encode($success),false);
  51. break;
  52. case 'deleteone' :
  53. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']);
  54. Display::display_confirmation_message(api_xml_http_response_encode($success),false);
  55. echo '<br />';
  56. break;
  57. }
  58. }
  59. // display sortable table with messages of the current user
  60. $table = new SortableTable('messages', 'get_number_of_messages_mask', 'get_message_data_mask', 3, get_number_of_messages_mask(),'DESC');
  61. $table->set_header(0, '', false,array ('style' => 'width:20px;'));
  62. $title=api_xml_http_response_encode(get_lang('Title'));
  63. $action=api_xml_http_response_encode(get_lang('Actions'));
  64. $table->set_header(1,api_xml_http_response_encode(get_lang('Status')),false,array('style' => 'width:30px;'));
  65. $table->set_header(2,api_xml_http_response_encode(get_lang('From')),false);
  66. $table->set_header(3,$title,false);
  67. $table->set_header(4,api_xml_http_response_encode(get_lang('Date')),false,array('style' => 'width:150px;'));
  68. $table->set_header(5,$action,false,array ('style' => 'width:100px;'));
  69. echo '<div id="div_content_table_data">';
  70. if ($request===true) {
  71. echo '<form name="form_send" id="form_send" action="" method="post">';
  72. echo '<input type="hidden" name="action" value="delete" />';
  73. $table->display();
  74. echo '</form>';
  75. if (get_number_of_messages_mask() > 0) {
  76. echo '<a href="javascript:void(0)" onclick="selectall_cheks()">'.api_xml_http_response_encode(get_lang('SelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  77. echo '<a href="javascript:void(0)" onclick="unselectall_cheks()">'.api_xml_http_response_encode(get_lang('UnSelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  78. echo '<button class="save" name="delete" type="button" value="'.api_xml_http_response_encode(get_lang('DeleteSelectedMessages')).'" onclick="submit_form(\'inbox\')">'.api_xml_http_response_encode(get_lang('DeleteSelectedMessages')).'</button>';
  79. }
  80. } else {
  81. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  82. $table->display();
  83. }
  84. echo '</div>';
  85. }
  86. function get_number_of_messages_mask() {
  87. return MessageManager::get_number_of_messages();
  88. }
  89. function get_message_data_mask($from, $number_of_items, $column, $direction) {
  90. $column='3';
  91. $direction='desc';
  92. //non set by SortableTable ?
  93. $number_of_items=get_number_of_messages_mask();
  94. return MessageManager::get_message_data($from, $number_of_items, $column, $direction);
  95. }
  96. function outbox_display() {
  97. $table_message = Database::get_main_table(TABLE_MESSAGE);
  98. $request=api_is_xml_http_request();
  99. global $charset;
  100. if ($_SESSION['social_exist']===true) {
  101. $redirect="#remote-tab-3";
  102. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  103. $success= get_lang('SelectedMessagesDeleted')."&nbsp<br><a href=\""."../social/index.php?$redirect\">".get_lang('BackToOutbox')."</a>";
  104. }else {
  105. $success=get_lang('SelectedMessagesDeleted')."&nbsp<br><a href=\""."../social/index.php?$redirect\">".get_lang('BackToOutbox')."</a>";
  106. }
  107. } else {
  108. $success= get_lang('SelectedMessagesDeleted')."&nbsp</b>"."<br><a href=\""."outbox.php\">".get_lang('BackToOutbox')."</a>";
  109. }
  110. if (isset ($_REQUEST['action'])) {
  111. switch ($_REQUEST['action']) {
  112. case 'delete' :
  113. $number_of_selected_messages = count($_POST['id']);
  114. if ($number_of_selected_messages!=0) {
  115. foreach ($_POST['id'] as $index => $message_id) {
  116. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id);
  117. }
  118. }
  119. Display::display_normal_message(api_xml_http_response_encode($success),false);
  120. break;
  121. case 'deleteone' :
  122. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']);
  123. Display::display_confirmation_message(api_xml_http_response_encode($success),false);
  124. echo '<br/>';
  125. break;
  126. }
  127. }
  128. // display sortable table with messages of the current user
  129. $table = new SortableTable('messages', 'get_number_of_messages_send_mask', 'get_message_data_send_mask', 3,get_number_of_messages_send_mask(),'DESC');
  130. $title=api_xml_http_response_encode(get_lang('Title'));
  131. $action=api_xml_http_response_encode(get_lang('Actions'));
  132. $table->set_header(0, '', false,array ('style' => 'width:20px;'));
  133. $table->set_header(1, api_xml_http_response_encode(get_lang('Status')),false,array ('style' => 'width:30px;'));
  134. $table->set_header(2, api_xml_http_response_encode(get_lang('To')),false);
  135. $table->set_header(3, $title,false);
  136. $table->set_header(4, api_xml_http_response_encode(get_lang('Date')),false,array ('style' => 'width:150px;'));
  137. $table->set_header(5,$action, false,array ('style' => 'width:100px;'));
  138. echo '<div id="div_content_table_data_sent">';
  139. if ($request===true) {
  140. echo '<form name="form_send_out" id="form_send_out" action="" method="post">';
  141. echo '<input type="hidden" name="action" value="delete" />';
  142. $table->display();
  143. echo '</form>';
  144. if (get_number_of_messages_send_mask() > 0) {
  145. echo '<a href="javascript:void(0)" onclick="selectall_cheks()">'.api_xml_http_response_encode(get_lang('SelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  146. echo '<a href="javascript:void(0)" onclick="unselectall_cheks()">'.api_xml_http_response_encode(get_lang('UnSelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  147. echo '<button class="save" name="delete" type="button" value="'.api_xml_http_response_encode(get_lang('DeleteSelectedMessages')).'" onclick="submit_form(\'outbox\')">'.api_xml_http_response_encode(get_lang('DeleteSelectedMessages')).'</button>';
  148. }
  149. } else {
  150. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  151. $table->display();
  152. }
  153. echo '</div>';
  154. }
  155. function get_number_of_messages_send_mask() {
  156. return MessageManager::get_number_of_messages_sent();
  157. }
  158. function get_message_data_send_mask($from, $number_of_items, $column, $direction) {
  159. $column='3';
  160. $direction='desc';
  161. //non set by SortableTable ?
  162. $number_of_items=get_number_of_messages_send_mask();
  163. return MessageManager::get_message_data_sent($from, $number_of_items, $column, $direction);
  164. }
  165. ?>