access_url_edit_sessions_to_url_functions.lib.php 2.1 KB

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