access_url_edit_users_to_url_functions.lib.php 2.6 KB

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