new_message.php 9.3 KB

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