glossary_ajax_request.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /* @todo move this file in the inc/ajax/ folder */
  5. /**
  6. * Glossary ajax request code
  7. * @package chamilo.glossary
  8. */
  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 = '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path();
  16. if (isset($_POST['glossary_id']) &&
  17. $_POST['glossary_id'] == strval(intval($_POST['glossary_id']))
  18. ) {
  19. $glossary_description_by_id = GlossaryManager::get_glossary_term_by_glossary_id(
  20. $_POST['glossary_id']
  21. );
  22. $glossary_description_by_id = str_replace(
  23. $path_image_search,
  24. $path_image,
  25. $glossary_description_by_id
  26. );
  27. echo api_xml_http_response_encode($glossary_description_by_id);
  28. } elseif (isset($_POST['glossary_data']) && $_POST['glossary_data'] == 'true') {
  29. //get_glossary_terms
  30. $glossary_data = GlossaryManager::get_glossary_terms();
  31. $glossary_all_data = array();
  32. if (count($glossary_data) > 0) {
  33. foreach ($glossary_data as $glossary_index => $glossary_value) {
  34. $glossary_all_data[] = $glossary_value['id'].'__|__|'.$glossary_value['name'];
  35. }
  36. $glossary_all_data = implode('[|.|_|.|-|.|]', $glossary_all_data);
  37. echo api_xml_http_response_encode($glossary_all_data);
  38. }
  39. } elseif(isset($_POST['glossary_name'])) {
  40. $my_glossary_name = Security::remove_XSS($_POST['glossary_name']);
  41. $my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8');
  42. $my_glossary_name = trim($my_glossary_name);
  43. $glossaryInfo = GlossaryManager::get_glossary_term_by_glossary_name(
  44. $my_glossary_name
  45. );
  46. $glossary_description = str_replace(
  47. $path_image_search,
  48. $path_image,
  49. $glossaryInfo['description']
  50. );
  51. if (is_null($glossary_description) || strlen(trim($glossary_description)) == 0) {
  52. echo api_xml_http_response_encode(get_lang('NoResults'));
  53. } else {
  54. echo api_xml_http_response_encode($glossary_description);
  55. }
  56. } else {
  57. echo api_xml_http_response_encode(get_lang('NoResults'));
  58. }
  59. Container::$legacyTemplate = 'layout_empty.html.twig';