access_url_edit_sessions_to_url_functions.lib.php 2.2 KB

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