new_message.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php // $Id: new_message.php 20301 2009-05-04 20:58:41Z 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. 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. $request=api_is_xml_http_request();
  46. $nameTools=($request===true) ? mb_convert_encoding(get_lang('Messages'),'UTF-8',$charset) : 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=($request===true) ? mb_convert_encoding(get_lang('ComposeMessage'),'UTF-8',$charset) : get_lang('ComposeMessage');
  94. $fck_attribute['Height'] = "150";
  95. $fck_attribute['Width'] = "95%";
  96. $fck_attribute['ToolbarSet'] = "Profil";
  97. /*
  98. ==============================================================================
  99. FUNCTIONS
  100. ==============================================================================
  101. */
  102. /**
  103. * Shows the compose area + a list of users to select from.
  104. */
  105. function show_compose_to_any ($user_id) {
  106. $online_user_list = MessageManager::get_online_user_list($user_id);
  107. $default['user_list'] = 0;
  108. $online_user_list=null;
  109. manage_form($default, $online_user_list);
  110. }
  111. function show_compose_reply_to_message ($message_id, $receiver_id) {
  112. global $charset;
  113. $table_message = Database::get_main_table(TABLE_MESSAGE);
  114. $query = "SELECT * FROM $table_message WHERE user_receiver_id=".$receiver_id." AND id='".$message_id."';";
  115. $result = api_sql_query($query,__FILE__,__LINE__);
  116. $row = Database::fetch_array($result);
  117. if (!isset($row[1])) {
  118. echo get_lang('InvalidMessageId');
  119. die();
  120. }
  121. echo get_lang('To').':&nbsp;<strong>'. GetFullUserName($row[1]).'</strong>';
  122. $default['title'] =mb_convert_encoding(get_lang('EnterTitle'),'UTF-8',$charset);
  123. $default['user_list'] = $row[1];
  124. manage_form($default);
  125. }
  126. function show_compose_to_user ($receiver_id) {
  127. global $charset;
  128. echo get_lang('To').':&nbsp;<strong>'. GetFullUserName($receiver_id).'</strong>';
  129. $default['title'] = mb_convert_encoding(get_lang('EnterTitle'),'UTF-8',$charset);
  130. $default['user_list'] = $receiver_id;
  131. manage_form($default);
  132. }
  133. function manage_form ($default, $select_from_user_list = null) {
  134. global $charset;
  135. $table_message = Database::get_main_table(TABLE_MESSAGE);
  136. $request=api_is_xml_http_request();
  137. if ($request===true) {
  138. $form = new FormValidator('compose_message','post','index.php?sendform=true#remote-tab-2');
  139. } else {
  140. $form = new FormValidator('compose_message');
  141. }
  142. if (isset($select_from_user_list)) {
  143. $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 ()'));
  144. $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
  145. $form->addElement('html','<div id="id_div_search" class="message-search">&nbsp;</div>');
  146. $form->addElement('hidden','user_list',0,array('id'=>'user_list'));
  147. } else {
  148. if ($default['user_list']==0) {
  149. $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 ()'));
  150. $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
  151. $form->addElement('html','<div id="id_div_search" class="message-search">&nbsp;</div>');
  152. }
  153. $form->addElement('hidden','user_list',0,array('id'=>'user_list'));
  154. }
  155. $form->add_textfield('title', mb_convert_encoding(get_lang('Title'),'UTF-8',$charset));
  156. $form->add_html_editor('content', '',false,false);
  157. if (isset($_GET['re_id'])) {
  158. $form->addElement('hidden','re_id',Security::remove_XSS($_GET['re_id']));
  159. $form->addElement('hidden','save_form','save_form');
  160. }
  161. $form->addElement('submit', 'compose',mb_convert_encoding(get_lang('Send'),'UTF-8',$charset));
  162. $form->setDefaults($default);
  163. if ($form->validate()) {
  164. $values = $form->exportValues();
  165. $receiver_user_id = $values['user_list'];
  166. $title = $values['title'];
  167. $content = $values['content'];
  168. //all is well, send the message
  169. MessageManager::send_message($receiver_user_id, $title, $content);
  170. MessageManager::display_success_message($receiver_user_id);
  171. } else {
  172. $form->display();
  173. }
  174. }
  175. /*
  176. ==============================================================================
  177. MAIN SECTION
  178. ==============================================================================
  179. */
  180. if (isset($_GET['rs'])) {
  181. $interbreadcrumb[] = array ('url' => 'inbox.php', 'name' => get_lang('Messages'));
  182. $interbreadcrumb[]= array (
  183. 'url' => '../social/'.$_SESSION['social_dest'],
  184. 'name' => get_lang('SocialNetwork')
  185. );
  186. } else {
  187. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('Messages'));
  188. $interbreadcrumb[]= array (
  189. 'url' => 'outbox.php',
  190. 'name' => get_lang('Outbox')
  191. );
  192. $interbreadcrumb[]= array (
  193. 'url' => 'inbox.php',
  194. 'name' => get_lang('Inbox')
  195. );
  196. }
  197. $interbreadcrumb[]= array (
  198. 'url' => '#',
  199. 'name' => get_lang('ComposeMessage')
  200. );
  201. if ($request===false) {
  202. Display::display_header('');
  203. }
  204. //api_display_tool_title($nameTools);
  205. echo '<div class=actions>';
  206. echo '<a onclick="close_div_show(\'div_content_messages\')" href="javascript:void(0)">'.Display::return_icon('folder_up.gif',mb_convert_encoding(get_lang('BackToInbox'),'UTF-8',$charset)).mb_convert_encoding(get_lang('BackToInbox'),'UTF-8',$charset).'</a>';
  207. echo '</div>';
  208. if (!isset($_POST['compose'])) {
  209. if(isset($_GET['re_id'])) {
  210. $message_id = $_GET['re_id'];
  211. $receiver_id = api_get_user_id();
  212. show_compose_reply_to_message($message_id, $receiver_id);
  213. } elseif(isset($_GET['send_to_user'])) {
  214. show_compose_to_user($_GET['send_to_user']);
  215. } else {
  216. show_compose_to_any($_user['user_id']);
  217. }
  218. } else {
  219. $restrict=isset($_POST['id_text_name']) ? $_POST['id_text_name'] : false;
  220. if ($restrict===false && isset($_GET['re_id'])) {
  221. }
  222. if (isset($_GET['re_id'])) {
  223. $default['title'] = mb_convert_encoding($_POST['title'],'UTF-8',$charset);
  224. $default['content'] = mb_convert_encoding($_POST['content'],'UTF-8',$charset);
  225. //$default['user_list'] = $_POST['user_list'];
  226. manage_form($default);
  227. } else {
  228. if ($restrict) {
  229. $default['title'] = mb_convert_encoding($_POST['title'],'UTF-8',$charset);
  230. $default['id_text_name'] = mb_convert_encoding($_POST['id_text_name'],'UTF-8',$charset);
  231. $default['user_list'] = $_POST['user_list'];
  232. manage_form($default);
  233. } else {
  234. Display::display_error_message(get_lang('ErrorSendingMessage'));
  235. }
  236. }
  237. }
  238. /*
  239. ==============================================================================
  240. FOOTER
  241. ==============================================================================
  242. */
  243. if ($request===false) {
  244. Display::display_footer();
  245. }
  246. ?>