glossary_ajax_request.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. *
  7. * @package chamilo.glossary
  8. */
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_course_script(true);
  11. /**
  12. * Search a term and return description from a glossary.
  13. */
  14. $charset = api_get_system_encoding();
  15. // Replace image path
  16. $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path();
  17. $path_image_search = '../..'.api_get_path(REL_COURSE_PATH).api_get_course_path();
  18. $glossaryId = isset($_POST['glossary_id']) ? (int) $_POST['glossary_id'] : 0;
  19. $description = get_lang('NoResults');
  20. if (!empty($glossaryId)) {
  21. $description = GlossaryManager::get_glossary_term_by_glossary_id($glossaryId);
  22. $description = str_replace($path_image_search, $path_image, $description);
  23. } elseif (isset($_POST['glossary_data']) && $_POST['glossary_data'] == 'true') {
  24. // get_glossary_terms
  25. $glossary_data = GlossaryManager::get_glossary_terms();
  26. $glossary_all_data = [];
  27. if (count($glossary_data) > 0) {
  28. foreach ($glossary_data as $glossary_index => $glossary_value) {
  29. $glossary_all_data[] = $glossary_value['id'].'__|__|'.$glossary_value['name'];
  30. }
  31. $description = implode('[|.|_|.|-|.|]', $glossary_all_data);
  32. }
  33. } elseif (isset($_POST['glossary_name'])) {
  34. $my_glossary_name = Security::remove_XSS($_POST['glossary_name']);
  35. $my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8');
  36. $my_glossary_name = trim($my_glossary_name);
  37. $glossaryInfo = GlossaryManager::get_glossary_term_by_glossary_name($my_glossary_name);
  38. $description = str_replace(
  39. $path_image_search,
  40. $path_image,
  41. $glossaryInfo['description']
  42. );
  43. if (is_null($description) || strlen(trim($description)) == 0) {
  44. $description = get_lang('NoResults');
  45. } else {
  46. $description = str_replace('class="glossary"', '', $description);
  47. }
  48. }
  49. echo api_xml_http_response_encode($description);