access_url_edit_courses_to_url_functions.lib.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Definition of the Accessurleditcoursestourl class
  5. * @package chamilo.library
  6. */
  7. /**
  8. * Access_url_edit_courses_to_url class
  9. * Contains several functions dealing with displaying,
  10. * editing,... of a Access_url_edit_courses_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. */
  17. class Accessurleditcoursestourl
  18. {
  19. /**
  20. * Search for a list of available courses by title or code, based on
  21. * a given string
  22. * @param string String to search for
  23. * @param int Deprecated param
  24. * @return string A formatted, xajax answer block
  25. * @assert () === false
  26. */
  27. function search_courses($needle, $id)
  28. {
  29. global $tbl_course;
  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 courses where username or firstname or lastname begins likes $needle
  38. $sql = 'SELECT code, title FROM '.$tbl_course.' u '.
  39. ' WHERE (title LIKE "'.$needle.'%" '.
  40. ' OR code LIKE "'.$needle.'%" '.
  41. ' ) '.
  42. ' ORDER BY title, code '.
  43. ' LIMIT 11';
  44. $rs = Database::query($sql);
  45. $i=0;
  46. while ($course = Database :: fetch_array($rs)) {
  47. $i++;
  48. if ($i<=10) {
  49. $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_url(\''.addslashes($course['code']).'\',\''.addslashes($course['title']).' ('.addslashes($course['code']).')'.'\')">'.$course['title'].' ('.$course['code'].')</a><br />';
  50. } else {
  51. $return .= '...<br />';
  52. }
  53. }
  54. }
  55. $xajax_response -> addAssign('ajax_list_courses','innerHTML',api_utf8_encode($return));
  56. return $xajax_response;
  57. }
  58. }