new_message.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php // $Id: new_message.php 21554 2009-06-21 20:58:47Z iflorespaz $
  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.paz@gmail.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. * This script shows a compose area (wysiwyg editor if supported, otherwise
  23. * a simple textarea) where the user can type a message.
  24. * There are three modes
  25. * - standard: type a message, select a user to send it to, press send
  26. * - reply on message (when pressing reply when viewing a message)
  27. * - send to specific user (when pressing send message in the who is online list)
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. // name of the language file that needs to be included
  35. $language_file= 'messages';
  36. $cidReset=true;
  37. require_once '../inc/global.inc.php';
  38. api_block_anonymous_users();
  39. if (api_get_setting('allow_message_tool')!='true'){
  40. api_not_allowed();
  41. }
  42. require_once'../messages/message.class.php';
  43. require_once api_get_path(LIBRARY_PATH).'/text.lib.php';
  44. require_once api_get_path(LIBRARY_PATH).'/formvalidator/FormValidator.class.php';
  45. $request=api_is_xml_http_request();
  46. $nameTools = api_xml_http_response_encode(get_lang('Messages'));
  47. /*
  48. -----------------------------------------------------------
  49. Constants and variables
  50. -----------------------------------------------------------
  51. */
  52. $htmlHeadXtra[]='
  53. <script language="javascript">
  54. function validate(form,list)
  55. {
  56. if(list.selectedIndex<0)
  57. {
  58. alert("Please select someone to send the message to.")
  59. return false
  60. }
  61. else
  62. return true
  63. }
  64. </script>';
  65. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  66. $htmlHeadXtra[] = '<script type="text/javascript">
  67. $(document).ready(function (){
  68. cont=0;
  69. $("#id_text_name").bind("keyup", function(){
  70. name=$("#id_text_name").get(0).value;
  71. $.ajax({
  72. contentType: "application/x-www-form-urlencoded",
  73. beforeSend: function(objeto) {
  74. /*$("#id_div_search").html("Searching...");*/ },
  75. type: "POST",
  76. url: "../social/select_options.php",
  77. data: "search="+name,
  78. success: function(datos){
  79. $("#id_div_search").html(datos)
  80. $("#id_search_name").bind("click", function(){
  81. name_option=$("select#id_search_name option:selected").text();
  82. code_option=$("select#id_search_name option:selected").val();
  83. $("#user_list").attr("value", code_option);
  84. $("#id_text_name").attr("value", name_option);
  85. $("#id_div_search").html("");
  86. cont++;
  87. });
  88. }
  89. });
  90. });
  91. });
  92. </script>';
  93. $nameTools = api_xml_http_response_encode(get_lang('ComposeMessage'));
  94. $fck_attribute['Height'] = "250";
  95. $fck_attribute['Width'] = "95%";
  96. $fck_attribute['ToolbarSet'] = "Profil";
  97. $fck_attribute['Config']['ToolbarStartExpanded']='false';
  98. /*
  99. ==============================================================================
  100. FUNCTIONS
  101. ==============================================================================
  102. */
  103. /**
  104. * Shows the compose area + a list of users to select from.
  105. */
  106. function show_compose_to_any ($user_id) {
  107. $online_user_list = MessageManager::get_online_user_list($user_id);
  108. $default['user_list'] = 0;
  109. $online_user_list=null;
  110. manage_form($default, $online_user_list);
  111. }
  112. function show_compose_reply_to_message ($message_id, $receiver_id) {
  113. global $charset;
  114. $table_message = Database::get_main_table(TABLE_MESSAGE);
  115. $query = "SELECT * FROM $table_message WHERE user_receiver_id=".$receiver_id." AND id='".$message_id."';";
  116. $result = api_sql_query($query,__FILE__,__LINE__);
  117. $row = Database::fetch_array($result);
  118. if (!isset($row[1])) {
  119. echo api_xml_http_response_encode(get_lang('InvalidMessageId'));
  120. die();
  121. }
  122. echo api_xml_http_response_encode(get_lang('To').':&nbsp;<strong>'. GetFullUserName($row[1]).'</strong>');
  123. $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle'));
  124. $default['user_list'] = $row[1];
  125. manage_form($default);
  126. }
  127. function show_compose_to_user ($receiver_id) {
  128. global $charset;
  129. echo get_lang('To').':&nbsp;<strong>'. GetFullUserName($receiver_id).'</strong>';
  130. $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle'));
  131. $default['user_list'] = $receiver_id;
  132. manage_form($default);
  133. }
  134. function manage_form ($default, $select_from_user_list = null) {
  135. global $charset;
  136. $table_message = Database::get_main_table(TABLE_MESSAGE);
  137. $request=api_is_xml_http_request();
  138. if ($request===true) {
  139. $form = new FormValidator('compose_message','post','index.php?sendform=true#remote-tab-2');
  140. } else {
  141. $form = new FormValidator('compose_message');
  142. }
  143. if (isset($select_from_user_list)) {
  144. $form->add_textfield('id_text_name', api_xml_http_response_encode(get_lang('SendMessageTo')),true,array('size' => 40,'id'=>'id_text_name','onkeyup'=>'send_request_and_search()','autocomplete'=>'off','style'=>'padding:0px'));
  145. $form->addRule('id_text_name', api_xml_http_response_encode(get_lang('ThisFieldIsRequired')), 'required');
  146. $form->addElement('html','<div id="id_div_search" style="padding:0px" class="message-select-box" >&nbsp;</div>');
  147. $form->addElement('hidden','user_list',0,array('id'=>'user_list'));
  148. } else {
  149. if ($default['user_list']==0) {
  150. $form->add_textfield('id_text_name', api_xml_http_response_encode(get_lang('SendMessageTo')),true,array('size' => 40,'id'=>'id_text_name','onkeyup'=>'send_request_and_search()','autocomplete'=>'off','style'=>'padding:0px'));
  151. $form->addRule('id_text_name', api_xml_http_response_encode(get_lang('ThisFieldIsRequired')), 'required');
  152. $form->addElement('html','<div id="id_div_search" style="padding:0px" class="message-select-box" >&nbsp;</div>');
  153. }
  154. $form->addElement('hidden','user_list',0,array('id'=>'user_list'));
  155. }
  156. $form->add_textfield('title', api_xml_http_response_encode(get_lang('Title')));
  157. $form->add_html_editor('content', '',false,false);
  158. if (isset($_GET['re_id'])) {
  159. $form->addElement('hidden','re_id',Security::remove_XSS($_GET['re_id']));
  160. $form->addElement('hidden','save_form','save_form');
  161. }
  162. $form->addElement('style_submit_button','compose',api_xml_http_response_encode(get_lang('SendMessage')),'class="save"');
  163. $form->setRequiredNote(api_xml_http_response_encode('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'));
  164. $form->setDefaults($default);
  165. if ($form->validate()) {
  166. $values = $form->exportValues();
  167. $receiver_user_id = $values['user_list'];
  168. $title = $values['title'];
  169. $content = $values['content'];
  170. //all is well, send the message
  171. MessageManager::send_message($receiver_user_id, $title, $content);
  172. MessageManager::display_success_message($receiver_user_id);
  173. } else {
  174. $form->display();
  175. }
  176. }
  177. /*
  178. ==============================================================================
  179. MAIN SECTION
  180. ==============================================================================
  181. */
  182. if (isset($_GET['rs'])) {
  183. $interbreadcrumb[] = array ('url' => 'inbox.php', 'name' => get_lang('Messages'));
  184. $interbreadcrumb[]= array (
  185. 'url' => '../social/'.$_SESSION['social_dest'],
  186. 'name' => get_lang('SocialNetwork')
  187. );
  188. } else {
  189. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('Messages'));
  190. $interbreadcrumb[]= array (
  191. 'url' => 'outbox.php',
  192. 'name' => get_lang('Outbox')
  193. );
  194. $interbreadcrumb[]= array (
  195. 'url' => 'inbox.php',
  196. 'name' => get_lang('Inbox')
  197. );
  198. }
  199. $interbreadcrumb[]= array (
  200. 'url' => '#',
  201. 'name' => get_lang('ComposeMessage')
  202. );
  203. if ($request===false) {
  204. Display::display_header('');
  205. }
  206. //api_display_tool_title($nameTools);
  207. echo '<div class=actions>';
  208. echo '<a onclick="close_div_show(\'div_content_messages\')" href="javascript:void(0)">'.Display::return_icon('folder_up.gif',api_xml_http_response_encode(get_lang('BackToInbox'))).api_xml_http_response_encode(get_lang('BackToInbox')).'</a>';
  209. echo '</div>';
  210. if (!isset($_POST['compose'])) {
  211. if(isset($_GET['re_id'])) {
  212. $message_id = $_GET['re_id'];
  213. $receiver_id = api_get_user_id();
  214. show_compose_reply_to_message($message_id, $receiver_id);
  215. } elseif(isset($_GET['send_to_user'])) {
  216. show_compose_to_user($_GET['send_to_user']);
  217. } else {
  218. show_compose_to_any($_user['user_id']);
  219. }
  220. } else {
  221. $restrict=isset($_POST['id_text_name']) ? $_POST['id_text_name'] : false;
  222. if ($restrict===false && isset($_GET['re_id'])) {
  223. }
  224. if (isset($_GET['re_id'])) {
  225. $default['title'] = api_xml_http_response_encode($_POST['title']);
  226. $default['content'] = api_xml_http_response_encode($_POST['content']);
  227. //$default['user_list'] = $_POST['user_list'];
  228. manage_form($default);
  229. } else {
  230. if ($restrict) {
  231. $default['title'] = api_xml_http_response_encode($_POST['title']);
  232. $default['id_text_name'] = api_xml_http_response_encode($_POST['id_text_name']);
  233. $default['user_list'] = $_POST['user_list'];
  234. manage_form($default);
  235. } else {
  236. Display::display_error_message(api_xml_http_response_encode(get_lang('ErrorSendingMessage')));
  237. }
  238. }
  239. }
  240. /*
  241. ==============================================================================
  242. FOOTER
  243. ==============================================================================
  244. */
  245. if ($request===false) {
  246. Display::display_footer();
  247. }
  248. ?>