glossary_ajax_request.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /* @todo move this file in the inc/ajax/ folder */
  4. /**
  5. * Glossary ajax request code
  6. * @package chamilo.glossary
  7. */
  8. require_once '../inc/global.inc.php';
  9. /**
  10. * Search a term and return description from a glossary.
  11. */
  12. $charset = api_get_system_encoding();
  13. //replace image path
  14. $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path();
  15. $path_image_search = '../../courses/'.api_get_course_path();
  16. if (isset($_POST['glossary_id']) &&
  17. $_POST['glossary_id'] == strval(intval($_POST['glossary_id']))
  18. ) {
  19. $glossary_id= Security::remove_XSS($_POST['glossary_id']);
  20. $glossary_description_by_id = GlossaryManager::get_glossary_term_by_glossary_id(
  21. $glossary_id
  22. );
  23. $glossary_description_by_id = str_replace(
  24. $path_image_search,
  25. $path_image,
  26. $glossary_description_by_id
  27. );
  28. echo api_xml_http_response_encode($glossary_description_by_id);
  29. } elseif (isset($_POST['glossary_data']) && $_POST['glossary_data']=='true') {
  30. //get_glossary_terms
  31. $glossary_data = GlossaryManager::get_glossary_terms();
  32. $glossary_all_data = array();
  33. if (count($glossary_data) > 0) {
  34. foreach ($glossary_data as $glossary_index => $glossary_value) {
  35. $glossary_all_data[] = $glossary_value['id'].'__|__|'.$glossary_value['name'];
  36. }
  37. $glossary_all_data = implode('[|.|_|.|-|.|]', $glossary_all_data);
  38. echo api_xml_http_response_encode($glossary_all_data);
  39. }
  40. } elseif(isset($_POST['glossary_name'])) {
  41. $my_glossary_name = Security::remove_XSS($_POST['glossary_name']);
  42. $my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8');
  43. $my_glossary_name = trim($my_glossary_name);
  44. $glossary_description = GlossaryManager::get_glossary_term_by_glossary_name(
  45. $my_glossary_name
  46. );
  47. $glossary_description = str_replace(
  48. $path_image_search,
  49. $path_image,
  50. $glossary_description
  51. );
  52. if (is_null($glossary_description) || strlen(trim($glossary_description)) == 0) {
  53. echo api_xml_http_response_encode(get_lang('NoResults'));
  54. } else {
  55. echo api_xml_http_response_encode($glossary_description);
  56. }
  57. } else {
  58. echo api_xml_http_response_encode(get_lang('NoResults'));
  59. }