glossary_ajax_request.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /**
  15. * Search a term and return description from a glossary.
  16. */
  17. $charset = api_get_system_encoding();
  18. //replace image path
  19. $path_image=api_get_path(WEB_COURSE_PATH).api_get_course_path();
  20. $path_image_search='../../courses/'.api_get_course_path();
  21. if (isset($_POST['glossary_id']) && $_POST['glossary_id']==strval(intval($_POST['glossary_id']))) {
  22. $glossary_id=Security::remove_XSS($_POST['glossary_id']);
  23. $glossary_description_by_id=GlossaryManager::get_glossary_term_by_glossary_id($glossary_id);
  24. $glossary_description_by_id=str_replace($path_image_search,$path_image,$glossary_description_by_id);
  25. echo api_xml_http_response_encode($glossary_description_by_id);
  26. } elseif (isset($_POST['glossary_data']) && $_POST['glossary_data']=='true') {
  27. //get_glossary_terms
  28. $glossary_data=GlossaryManager::get_glossary_terms();
  29. $glossary_all_data=array();
  30. if (count($glossary_data)>0) {
  31. foreach ($glossary_data as $glossary_index=>$glossary_value) {
  32. $glossary_all_data[]=$glossary_value['id'].'__|__|'.$glossary_value['name'];
  33. }
  34. $glossary_all_data=implode('[|.|_|.|-|.|]',$glossary_all_data);
  35. echo api_xml_http_response_encode($glossary_all_data);
  36. }
  37. } elseif(isset($_POST['glossary_name'])) {
  38. $my_glossary_name=Security::remove_XSS($_POST['glossary_name']);
  39. $my_glossary_name=api_convert_encoding($my_glossary_name,$charset,'UTF-8');
  40. $my_glossary_name=trim($my_glossary_name);
  41. $glossary_description=GlossaryManager::get_glossary_term_by_glossary_name($my_glossary_name);
  42. $glossary_description=str_replace($path_image_search,$path_image,$glossary_description);
  43. if (is_null($glossary_description) || strlen(trim($glossary_description))==0) {
  44. echo api_xml_http_response_encode(get_lang('NoResults'));
  45. } else {
  46. echo api_xml_http_response_encode($glossary_description);
  47. }
  48. } else {
  49. echo api_xml_http_response_encode(get_lang('NoResults'));
  50. }