functions.inc.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php // $Id: functions.inc.php 9680 2006-10-24 13:23:45Z evie_em $
  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. include_once(api_get_path(LIBRARY_PATH).'/online.inc.php');
  19. define ("MESSAGES_DATABASE", "messages");
  20. /**
  21. * Displays a select list containing the users
  22. * who are currently online. Used when composing a message.
  23. */
  24. function display_select_user_list($_uid,$_name,$width,$size)
  25. {
  26. $MINUTE=30;
  27. global $statsDbName;
  28. $userlist = WhoIsOnline($_uid,$statsDbName,$MINUTE);
  29. echo '<select size="'.$size.'" style="width: '.$width.'px;" name="'.$_name.'">';
  30. foreach($userlist as $row)
  31. echo "<option value=\"$row[0]\">".GetFullUserName($row[0]).($_uid==$row[0]?("&nbsp;(".get_lang('Myself').")"):(""))."</option>\n";
  32. echo "</select>";
  33. }
  34. /**
  35. * Displays info stating that the message is sent successfully.
  36. */
  37. function display_success_message($uid)
  38. {
  39. $success= "<p style=\"text-align: center\">".
  40. get_lang('MessageSentTo').
  41. "&nbsp;<b>".
  42. GetFullUserName($uid).
  43. "</b>".
  44. "<br><a href=\"".
  45. "inbox.php\">".
  46. get_lang('BackToInbox').
  47. "</a>";
  48. Display::display_normal_message($success);
  49. }
  50. /**
  51. * @todo this function seems no longer user
  52. * but is still mentioned in comments, what can be the use?
  53. */
  54. function validate_text($texto)
  55. {
  56. $MAX_SIZE = 60; /*Tama� m�imo de caracteres por l�ea*/
  57. $i=0;
  58. $lines = array(); /*Arreglo que contendr�las l�eas del texto*/
  59. $token = strtok($texto, "\n");
  60. while($token)
  61. {
  62. $lines[$i]= $token;
  63. $token = strtok("\n");
  64. $i++;
  65. }
  66. $modificado= "";
  67. for($i=0; $i<count($lines); $i++ )
  68. {
  69. if(strlen($lines[$i])>$MAX_SIZE + 1)
  70. {
  71. $modificado2= substr($lines[$i], 0, $MAX_SIZE);
  72. for($j=$MAX_SIZE; $j<strlen($lines[$i]); $j+=$MAX_SIZE)
  73. {
  74. $modificado2 = $modificado2."\n".substr($lines[$i], $j, $MAX_SIZE);
  75. }
  76. }
  77. else
  78. {
  79. $modificado2= $lines[$i];
  80. }
  81. $modificado = $modificado.$modificado2."\n";
  82. }
  83. $modificado = substr($modificado, 0 ,strlen($modificado)-1);
  84. $modificado = str_replace("&", "&#038", $modificado); // �em
  85. $modificado = str_replace("<", "&#60", $modificado); // para evitar que lo convierta en html
  86. $modificado = str_replace(">", "&#62", $modificado); // �em
  87. return $modificado;
  88. }
  89. /**
  90. * Displays the wysiwyg html editor.
  91. */
  92. function display_html_editor_area($name,$resp)
  93. {
  94. api_disp_html_area($name, 'Type your message here.', '', '100%');
  95. }
  96. /**
  97. * Get the new messages for the current user from the database.
  98. */
  99. function get_new_messages()
  100. {
  101. if (! isset($_SESSION['_uid'])) return false;
  102. $i=0;
  103. $query = "SELECT * FROM `".MESSAGES_DATABASE."` WHERE id_reciv=".$_SESSION['_uid']." AND status=1;";
  104. $result = api_sql_query($query,__FILE__,__LINE__);
  105. while ($result_row = mysql_fetch_array($result)) $i++;
  106. return $i;
  107. }
  108. /**
  109. * Get the list of user_ids of users who are online.
  110. */
  111. function users_connected_by_id()
  112. {
  113. global $statsDbName, $_uid;
  114. $MINUTE=30;
  115. $user_connect = WhoIsOnline($_uid,$statsDbName,$MINUTE);
  116. for ($i=0; $i<count($user_connect); $i++)
  117. {
  118. $user_id_list[$i]=$user_connect[$i][0];
  119. }
  120. return $user_id_list;
  121. }
  122. /**
  123. * Gets the total number of messages, used for the inbox sortable table
  124. */
  125. function get_number_of_messages()
  126. {
  127. $sql_query = "SELECT COUNT(*) as number_messages FROM `".MESSAGES_DATABASE."` WHERE id_reciv=".$_SESSION['_uid'];
  128. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  129. $result = mysql_fetch_array($sql_result);
  130. return $result['number_messages'];
  131. }
  132. /**
  133. * Gets information about some messages, used for the inbox sortable table
  134. * @param int $from
  135. * @param int $number_of_items
  136. * @param string $direction
  137. */
  138. function get_message_data($from, $number_of_items, $column, $direction)
  139. {
  140. $sql_query = "SELECT id as col0, id_rem as col1, fecha as col2 FROM `".MESSAGES_DATABASE."` WHERE id_reciv=".$_SESSION['_uid']." ORDER BY col$column $direction LIMIT $from,$number_of_items";
  141. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  142. $i = 0;
  143. $message_list = array ();
  144. while ($result = mysql_fetch_row($sql_result))
  145. {
  146. $message[0] = $result[0];
  147. $message[1] = GetFullUserName($result[1]);
  148. $message[1] = "<a href=\"view_message.php?id=".$result[0]."\" title=\"$texto\">".GetFullUserName($result[1])."</a></td>";
  149. $message[2] = $result[2]; //date stays the same
  150. $message[3] = '<a href="new_message.php?re_id='.$result[0].'"><img src="'.api_get_path(WEB_IMG_PATH).'forum.gif" alt="'.get_lang("ReplyToMessage").'" align="middle"></img></a>';
  151. $message_list[] = $message;
  152. $i++;
  153. }
  154. return $message_list;
  155. }
  156. /**
  157. * Displays the inbox of a user, listing all messages.
  158. * In the process of moving towards sortable table.
  159. */
  160. function inbox_display()
  161. {
  162. //delete messages if delete action was chosen
  163. if (isset ($_POST['action']))
  164. {
  165. switch ($_POST['action'])
  166. {
  167. case 'delete' :
  168. $number_of_selected_messages = count($_POST['id']);
  169. foreach ($_POST['id'] as $index => $message_id)
  170. {
  171. $query = "DELETE FROM ".MESSAGES_DATABASE." WHERE id_reciv=".$_SESSION['_uid']." AND id='$message_id'";
  172. api_sql_query($query,__FILE__,__LINE__);
  173. }
  174. Display :: display_normal_message(get_lang('SelectedMessagesDeleted'));
  175. break;
  176. }
  177. }
  178. // display sortable table with messages of the current user
  179. $table = new SortableTable('messages', 'get_number_of_messages', 'get_message_data', 1);
  180. $table->set_header(0, '', false);
  181. $table->set_header(1, get_lang('From'));
  182. $table->set_header(2, get_lang('Date'));
  183. $table->set_header(3, get_lang("ReplyToMessage"), false);
  184. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  185. $table->display();
  186. }
  187. ?>