access_url_edit_sessions_to_url_functions.lib.php 2.1 KB

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