access_url_edit_users_to_url_functions.lib.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Accessurledituserstourl class definition
  5. * @package chamilo.library
  6. */
  7. /**
  8. * Accessurledituserstourl class definition
  9. * Contains several functions dealing with displaying,
  10. * editing,... of a Access_url_edit_users_to_url_functions
  11. *
  12. * @version 1.0
  13. * @author Toon Keppens <toon@vi-host.net>
  14. * @author Julio Montoya - Cleaning code
  15. * @author Ricardo Rodriguez - Separated the function and code
  16. * @package chamilo.library
  17. */
  18. class Accessurledituserstourl
  19. {
  20. /**
  21. * Search users by username, firstname or lastname, based on the given
  22. * search string
  23. * @param string Search string
  24. * @param int Deprecated param
  25. * @return string Xajax response block
  26. * @assert () === false
  27. */
  28. function search_users($needle, $id)
  29. {
  30. global $tbl_user;
  31. $xajax_response = new xajaxResponse();
  32. $return = '';
  33. if (!empty($needle)) {
  34. // xajax send utf8 datas... datas in db can be non-utf8 datas
  35. $charset = api_get_system_encoding();
  36. $needle = api_convert_encoding($needle, $charset, 'utf-8');
  37. $needle = Database::escape_string($needle);
  38. // search users where username or firstname or lastname begins likes $needle
  39. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  40. $sql = 'SELECT u.user_id, username, lastname, firstname FROM '.$tbl_user.' u '.
  41. ' WHERE (username LIKE "'.$needle.'%" '.
  42. ' OR firstname LIKE "'.$needle.'%" '.
  43. ' OR lastname LIKE "'.$needle.'%") '.
  44. $order_clause .
  45. ' LIMIT 11';
  46. $rs = Database::query($sql);
  47. $i=0;
  48. while ($user = Database :: fetch_array($rs)) {
  49. $i++;
  50. if ($i<=10) {
  51. $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_url(\''.addslashes($user['user_id']).'\',\''.api_get_person_name(addslashes($user['firstname']), addslashes($user['lastname'])).' ('.addslashes($user['username']).')'.'\')">'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</a><br />';
  52. } else {
  53. $return .= '...<br />';
  54. }
  55. }
  56. }
  57. $xajax_response -> addAssign('ajax_list_users','innerHTML',api_utf8_encode($return));
  58. return $xajax_response;
  59. }
  60. }