glossary_ajax_request.php 2.3 KB

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