functions.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author
  19. * @version $Id: functions.inc.php 10675 2007-01-11 13:03:10Z bmol $
  20. * @todo use database library
  21. */
  22. include_once(api_get_path(LIBRARY_PATH).'/online.inc.php');
  23. define ("MESSAGES_DATABASE", "messages");
  24. function get_online_user_list($current_user_id)
  25. {
  26. $MINUTE=30;
  27. global $_configuration;
  28. $userlist = WhoIsOnline($current_user_id,$_configuration['statistics_database'],$MINUTE);
  29. foreach($userlist as $row)
  30. {
  31. $receiver_id = $row[0];
  32. $online_user_list[$receiver_id] = GetFullUserName($receiver_id).($current_user_id==$receiver_id?("&nbsp;(".get_lang('Myself').")"):(""));
  33. }
  34. return $online_user_list;
  35. }
  36. /**
  37. * Displays info stating that the message is sent successfully.
  38. */
  39. function display_success_message($uid)
  40. {
  41. $success= "<p style=\"text-align: center\">".
  42. get_lang('MessageSentTo').
  43. "&nbsp;<b>".
  44. GetFullUserName($uid).
  45. "</b>".
  46. "<br><a href=\"".
  47. "inbox.php\">".
  48. get_lang('BackToInbox').
  49. "</a>";
  50. Display::display_normal_message($success);
  51. }
  52. /**
  53. * @todo this function seems no longer user
  54. * but is still mentioned in comments, what can be the use?
  55. */
  56. function validate_text($texto)
  57. {
  58. $MAX_SIZE = 60; /*Tama� m�imo de caracteres por l�ea*/
  59. $i=0;
  60. $lines = array(); /*Arreglo que contendr�las l�eas del texto*/
  61. $token = strtok($texto, "\n");
  62. while($token)
  63. {
  64. $lines[$i]= $token;
  65. $token = strtok("\n");
  66. $i++;
  67. }
  68. $modificado= "";
  69. for($i=0; $i<count($lines); $i++ )
  70. {
  71. if(strlen($lines[$i])>$MAX_SIZE + 1)
  72. {
  73. $modificado2= substr($lines[$i], 0, $MAX_SIZE);
  74. for($j=$MAX_SIZE; $j<strlen($lines[$i]); $j+=$MAX_SIZE)
  75. {
  76. $modificado2 = $modificado2."\n".substr($lines[$i], $j, $MAX_SIZE);
  77. }
  78. }
  79. else
  80. {
  81. $modificado2= $lines[$i];
  82. }
  83. $modificado = $modificado.$modificado2."\n";
  84. }
  85. $modificado = substr($modificado, 0 ,strlen($modificado)-1);
  86. $modificado = str_replace("&", "&#038", $modificado); // �em
  87. $modificado = str_replace("<", "&#60", $modificado); // para evitar que lo convierta en html
  88. $modificado = str_replace(">", "&#62", $modificado); // �em
  89. return $modificado;
  90. }
  91. /**
  92. * Displays the wysiwyg html editor.
  93. */
  94. function display_html_editor_area($name,$resp)
  95. {
  96. api_disp_html_area($name, 'Type your message here.', '', '100%');
  97. }
  98. /**
  99. * Get the new messages for the current user from the database.
  100. */
  101. function get_new_messages()
  102. {
  103. if (!api_get_user_id())
  104. {
  105. return false;
  106. }
  107. $i=0;
  108. $query = "SELECT * FROM `".MESSAGES_DATABASE."` WHERE id_receiver=".api_get_user_id()." AND status=1;";
  109. $result = api_sql_query($query,__FILE__,__LINE__);
  110. $i = mysql_num_rows($result);
  111. return $i;
  112. }
  113. /**
  114. * Get the list of user_ids of users who are online.
  115. */
  116. function users_connected_by_id()
  117. {
  118. global $_configuration, $_user;
  119. $MINUTE=30;
  120. $user_connect = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],$MINUTE);
  121. for ($i=0; $i<count($user_connect); $i++)
  122. {
  123. $user_id_list[$i]=$user_connect[$i][0];
  124. }
  125. return $user_id_list;
  126. }
  127. /**
  128. * Gets the total number of messages, used for the inbox sortable table
  129. */
  130. function get_number_of_messages()
  131. {
  132. $sql_query = "SELECT COUNT(*) as number_messages FROM `".MESSAGES_DATABASE."` WHERE id_receiver=".$_SESSION['_user']['user_id'];
  133. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  134. $result = mysql_fetch_array($sql_result);
  135. return $result['number_messages'];
  136. }
  137. /**
  138. * Gets information about some messages, used for the inbox sortable table
  139. * @param int $from
  140. * @param int $number_of_items
  141. * @param string $direction
  142. */
  143. function get_message_data($from, $number_of_items, $column, $direction)
  144. {
  145. $sql_query = "SELECT id as col0, id_sender as col1, title as col2, date as col3 FROM `".MESSAGES_DATABASE."` WHERE id_receiver=".$_SESSION['_user']['user_id']." ORDER BY col$column $direction LIMIT $from,$number_of_items";
  146. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  147. $i = 0;
  148. $message_list = array ();
  149. while ($result = mysql_fetch_row($sql_result))
  150. {
  151. $message[0] = $result[0];
  152. $message[1] = GetFullUserName($result[1]);
  153. //$message[1] = "<a href=\"view_message.php?id=".$result[0]."\" title=\"$texto\">".GetFullUserName($result[1])."</a>";
  154. $message[2] = '<a href="view_message.php?id='.$result[0].'">'.$result[2].'</a>';
  155. $message[3] = $result[3]; //date stays the same
  156. $message[4] = '<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>';
  157. $message_list[] = $message;
  158. $i++;
  159. }
  160. return $message_list;
  161. }
  162. /**
  163. * Displays the inbox of a user, listing all messages.
  164. * In the process of moving towards sortable table.
  165. */
  166. function inbox_display()
  167. {
  168. //delete messages if delete action was chosen
  169. if (isset ($_POST['action']))
  170. {
  171. switch ($_POST['action'])
  172. {
  173. case 'delete' :
  174. $number_of_selected_messages = count($_POST['id']);
  175. foreach ($_POST['id'] as $index => $message_id)
  176. {
  177. $query = "DELETE FROM ".MESSAGES_DATABASE." WHERE id_receiver=".api_get_user_id()." AND id='".mysql_real_escape_string($message_id)."'";
  178. api_sql_query($query,__FILE__,__LINE__);
  179. }
  180. Display :: display_normal_message(get_lang('SelectedMessagesDeleted'));
  181. break;
  182. }
  183. }
  184. // display sortable table with messages of the current user
  185. $table = new SortableTable('messages', 'get_number_of_messages', 'get_message_data', 1);
  186. $table->set_header(0, '', false);
  187. $table->set_header(1, get_lang('From'));
  188. $table->set_header(2, get_lang('Title'));
  189. $table->set_header(3, get_lang('Date'));
  190. $table->set_header(4, get_lang("ReplyToMessage"), false);
  191. $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages')));
  192. $table->display();
  193. }
  194. ?>