message.lib.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // $charset = api_get_setting('platform_charset');
  24. $table_message = Database::get_main_table(TABLE_MESSAGE);
  25. $request=api_is_xml_http_request();
  26. if ($_SESSION['social_exist']===true) {
  27. $redirect="#remote-tab-2";
  28. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  29. $success= get_lang('SelectedMessagesDeleted');
  30. } else {
  31. $success= get_lang('SelectedMessagesDeleted');
  32. }
  33. } else {
  34. $success= get_lang('SelectedMessagesDeleted');
  35. }
  36. if (isset ($_REQUEST['action'])) {
  37. switch ($_REQUEST['action']) {
  38. case 'delete' :
  39. $number_of_selected_messages = count($_POST['id']);
  40. foreach ($_POST['id'] as $index => $message_id) {
  41. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id);
  42. }
  43. Display::display_normal_message(api_xml_http_response_encode($success),false);
  44. break;
  45. case 'deleteone' :
  46. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']);
  47. Display::display_confirmation_message(api_xml_http_response_encode($success),false);
  48. echo '<br />';
  49. break;
  50. }
  51. }
  52. // display sortable table with messages of the current user
  53. $table = new SortableTable('messages', 'get_number_of_messages_mask', 'get_message_data_mask', 3, get_number_of_messages_mask(),'DESC');
  54. $table->set_header(0, '', false,array ('style' => 'width:20px;'));
  55. $title=api_xml_http_response_encode(get_lang('Title'));
  56. $action=api_xml_http_response_encode(get_lang('Actions'));
  57. $table->set_header(1,api_xml_http_response_encode(get_lang('Status')),false,array('style' => 'width:30px;'));
  58. $table->set_header(2,api_xml_http_response_encode(get_lang('From')),false);
  59. $table->set_header(3,$title,false);
  60. $table->set_header(4,api_xml_http_response_encode(get_lang('Date')),false,array('style' => 'width:150px;'));
  61. $table->set_header(5,$action,false,array ('style' => 'width:100px;'));
  62. echo '<div id="div_content_table_data">';
  63. if ($request===true) {
  64. echo '<form name="form_send" id="form_send" action="" method="post">';
  65. echo '<input type="hidden" name="action" value="delete" />';
  66. $table->display();
  67. echo '</form>';
  68. if (get_number_of_messages_mask() > 0) {
  69. echo '<a href="javascript:void(0)" onclick="selectall_cheks()">'.api_xml_http_response_encode(get_lang('SelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  70. echo '<a href="javascript:void(0)" onclick="unselectall_cheks()">'.api_xml_http_response_encode(get_lang('UnSelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  71. 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>';
  72. }
  73. } else {
  74. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  75. $table->display();
  76. }
  77. echo '</div>';
  78. }
  79. function get_number_of_messages_mask() {
  80. return MessageManager::get_number_of_messages();
  81. }
  82. function get_message_data_mask($from, $number_of_items, $column, $direction) {
  83. $column='3';
  84. $direction='desc';
  85. //non set by SortableTable ?
  86. $number_of_items=get_number_of_messages_mask();
  87. return MessageManager::get_message_data($from, $number_of_items, $column, $direction);
  88. }
  89. function outbox_display() {
  90. $table_message = Database::get_main_table(TABLE_MESSAGE);
  91. $request=api_is_xml_http_request();
  92. global $charset;
  93. if ($_SESSION['social_exist']===true) {
  94. $redirect="#remote-tab-3";
  95. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  96. $success= get_lang('SelectedMessagesDeleted')."&nbsp<br><a href=\""."../social/index.php?$redirect\">".get_lang('BackToOutbox')."</a>";
  97. }else {
  98. $success=get_lang('SelectedMessagesDeleted')."&nbsp<br><a href=\""."../social/index.php?$redirect\">".get_lang('BackToOutbox')."</a>";
  99. }
  100. } else {
  101. $success= get_lang('SelectedMessagesDeleted')."&nbsp</b>"."<br><a href=\""."outbox.php\">".get_lang('BackToOutbox')."</a>";
  102. }
  103. if (isset ($_REQUEST['action'])) {
  104. switch ($_REQUEST['action']) {
  105. case 'delete' :
  106. $number_of_selected_messages = count($_POST['id']);
  107. if ($number_of_selected_messages!=0) {
  108. foreach ($_POST['id'] as $index => $message_id) {
  109. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id);
  110. }
  111. }
  112. Display::display_normal_message(api_xml_http_response_encode($success),false);
  113. break;
  114. case 'deleteone' :
  115. MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']);
  116. Display::display_confirmation_message(api_xml_http_response_encode($success),false);
  117. echo '<br/>';
  118. break;
  119. }
  120. }
  121. // display sortable table with messages of the current user
  122. $table = new SortableTable('messages', 'get_number_of_messages_send_mask', 'get_message_data_send_mask', 3,get_number_of_messages_send_mask(),'DESC');
  123. $title=api_xml_http_response_encode(get_lang('Title'));
  124. $action=api_xml_http_response_encode(get_lang('Actions'));
  125. $table->set_header(0, '', false,array ('style' => 'width:20px;'));
  126. $table->set_header(1, api_xml_http_response_encode(get_lang('Status')),false,array ('style' => 'width:30px;'));
  127. $table->set_header(2, api_xml_http_response_encode(get_lang('To')),false);
  128. $table->set_header(3, $title,false);
  129. $table->set_header(4, api_xml_http_response_encode(get_lang('Date')),false,array ('style' => 'width:150px;'));
  130. $table->set_header(5,$action, false,array ('style' => 'width:100px;'));
  131. echo '<div id="div_content_table_data_sent">';
  132. if ($request===true) {
  133. echo '<form name="form_send_out" id="form_send_out" action="" method="post">';
  134. echo '<input type="hidden" name="action" value="delete" />';
  135. $table->display();
  136. echo '</form>';
  137. if (get_number_of_messages_send_mask() > 0) {
  138. echo '<a href="javascript:void(0)" onclick="selectall_cheks()">'.api_xml_http_response_encode(get_lang('SelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  139. echo '<a href="javascript:void(0)" onclick="unselectall_cheks()">'.api_xml_http_response_encode(get_lang('UnSelectAll')).'</a>&nbsp;&nbsp;&nbsp;';
  140. 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>';
  141. }
  142. } else {
  143. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  144. $table->display();
  145. }
  146. echo '</div>';
  147. }
  148. function get_number_of_messages_send_mask() {
  149. return MessageManager::get_number_of_messages_sent();
  150. }
  151. function get_message_data_send_mask($from, $number_of_items, $column, $direction) {
  152. $column='3';
  153. $direction='desc';
  154. //non set by SortableTable ?
  155. $number_of_items=get_number_of_messages_send_mask();
  156. return MessageManager::get_message_data_sent($from, $number_of_items, $column, $direction);
  157. }
  158. ?>