new_message.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php // $Id: new_message.php 12996 2007-09-11 14:49:05Z elixir_inter $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) Facultad de Matematicas, UADY (México)
  6. Copyright (c) Evie, Free University of Brussels (Belgium)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * This script shows a compose area (wysiwyg editor if supported, otherwise
  20. * a simple textarea) where the user can type a message.
  21. * There are three modes
  22. * - standard: type a message, select a user to send it to, press send
  23. * - reply on message (when pressing reply when viewing a message)
  24. * - send to specific user (when pressing send message in the who is online list)
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. // name of the language file that needs to be included
  32. $language_file= "messages";
  33. $cidReset=true;
  34. include_once('../../main/inc/global.inc.php');
  35. echo $_SESSION['prueba'];
  36. api_block_anonymous_users();
  37. require_once('./functions.inc.php');
  38. require_once(api_get_path(LIBRARY_PATH).'/text.lib.php');
  39. require_once(api_get_path(LIBRARY_PATH).'/formvalidator/FormValidator.class.php');
  40. /*
  41. -----------------------------------------------------------
  42. Constants and variables
  43. -----------------------------------------------------------
  44. */
  45. $htmlHeadXtra[]='
  46. <script language="javascript">
  47. function validate(form,list)
  48. {
  49. if(list.selectedIndex<0)
  50. {
  51. alert("Please select someone to send the message to.")
  52. return false
  53. }
  54. else
  55. return true
  56. }
  57. </script>';
  58. $nameTools = get_lang('ComposeMessage');
  59. /*
  60. ==============================================================================
  61. FUNCTIONS
  62. ==============================================================================
  63. */
  64. /**
  65. * Shows the compose area + a list of users to select from.
  66. */
  67. function show_compose_to_any($user_id)
  68. {
  69. $online_user_list = get_online_user_list($user_id);
  70. $default['user_list'] = $user_id;
  71. manage_form($default, $online_user_list);
  72. }
  73. function show_compose_reply_to_message($message_id, $receiver_id)
  74. {
  75. $query = "SELECT * FROM `".MESSAGES_DATABASE."` WHERE id_receiver=".$receiver_id." AND id='".$message_id."';";
  76. $result = api_sql_query($query,__FILE__,__LINE__);
  77. $row = mysql_fetch_array($result);
  78. if(!isset($row[1]))
  79. {
  80. echo get_lang('InvalidMessageId');
  81. die();
  82. }
  83. echo get_lang('To').':&nbsp;<strong>'. GetFullUserName($row[1]).'</strong>';
  84. $default['title'] = "Please enter a title";
  85. $default['user_list'] = $row[1];
  86. manage_form($default);
  87. }
  88. function show_compose_to_user($receiver_id)
  89. {
  90. echo get_lang('To').':&nbsp;<strong>'. GetFullUserName($receiver_id).'</strong>';
  91. $default['title'] = "Please enter a title";
  92. $default['user_list'] = $receiver_id;
  93. manage_form($default);
  94. }
  95. function manage_form($default, $select_from_user_list = null)
  96. {
  97. $form = new FormValidator('compose_message');
  98. if (isset($select_from_user_list))
  99. {
  100. $form->addElement('select', 'user_list', get_lang('SendMessageTo'), $select_from_user_list);
  101. }
  102. else
  103. {
  104. $form->addElement('hidden', 'user_list');
  105. }
  106. $form->add_textfield('title', get_lang('Title'));
  107. $form->add_html_editor('content', get_lang('Content'));
  108. $form->addElement('submit', 'compose', get_lang('Ok'));
  109. $form->setDefaults($default);
  110. if( $form->validate() )
  111. {
  112. $values = $form->exportValues();
  113. $receiver_user_id = $values['user_list'];
  114. $title = mysql_real_escape_string($values['title']);
  115. $content = mysql_real_escape_string($values['content']);
  116. //all is well, send the message
  117. $id_tmp = api_get_user_id().$receiver_user_id.date('d-D-w-m-Y-H-s').microtime().rand();
  118. $id_msg = md5($id_tmp);
  119. $query = "INSERT INTO `".MESSAGES_DATABASE."` ( `id`, `id_sender`, `id_receiver`, `status`, `date`, `title`, `content` ) ".
  120. " VALUES (".
  121. "' ".$id_msg ."' , '".api_get_user_id()."', '".$receiver_user_id."', '1', '".date('Y-m-d H:i:s')."','".$title."','".$content."'".
  122. ");";
  123. @api_sql_query($query,__FILE__,__LINE__);
  124. display_success_message($receiver_user_id);
  125. }
  126. else
  127. {
  128. $form->display();
  129. }
  130. }
  131. /*
  132. ==============================================================================
  133. MAIN SECTION
  134. ==============================================================================
  135. */
  136. $interbreadcrumb[] = array ("url" => 'inbox.php', "name" => get_lang('Messages'));
  137. Display::display_header($nameTools, get_lang("ComposeMessage"));
  138. api_display_tool_title($nameTools);
  139. if(!isset($_POST['compose']))
  140. {
  141. if(isset($_GET['re_id']))
  142. {
  143. $message_id = $_GET['re_id'];
  144. $receiver_id = api_get_user_id();
  145. show_compose_reply_to_message($message_id, $receiver_id);
  146. }
  147. else if(isset($_GET['send_to_user']))
  148. {
  149. show_compose_to_user($_GET['send_to_user']);
  150. }
  151. else
  152. {
  153. show_compose_to_any($_user['user_id']);
  154. }
  155. }
  156. else
  157. {
  158. if(api_get_user_id() && isset($_POST['user_list']) && isset($_POST['content']))
  159. {
  160. $default['title'] = $_POST['title'];
  161. $default['user_list'] = $_POST['user_list'];
  162. manage_form($default);
  163. }
  164. else
  165. Display::display_error_message(get_lang('ErrorSendingMessage'));
  166. }
  167. /*
  168. ==============================================================================
  169. FOOTER
  170. ==============================================================================
  171. */
  172. Display::display_footer();
  173. ?>