sub_language_ajax.inc.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraField;
  4. /**
  5. * Sub language AJAX script to update variables.
  6. *
  7. * @package chamilo.admin.sub_language
  8. */
  9. $this_script = 'sub_language';
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_protect_admin_script();
  12. $new_language = Security::remove_XSS($_REQUEST['new_language']);
  13. $language_variable = Security::remove_XSS($_REQUEST['variable_language']);
  14. $file_id = intval($_REQUEST['file_id']);
  15. if (isset($new_language) && isset($language_variable) && isset($file_id)) {
  16. $file_language = $language_files_to_load[$file_id].'.inc.php';
  17. $id_language = intval($_REQUEST['id']);
  18. $sub_language_id = intval($_REQUEST['sub']);
  19. $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id);
  20. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'].'/'.$file_language;
  21. $all_file_of_directory = SubLanguageManager::get_all_language_variable_in_file($path_folder);
  22. $return_value = SubLanguageManager::add_file_in_language_directory($path_folder);
  23. //update variable language
  24. // Replace double quotes to avoid parse errors
  25. $new_language = str_replace('"', '\"', $new_language);
  26. // Replace new line signs to avoid parse errors - see #6773
  27. $new_language = str_replace("\n", "\\n", $new_language);
  28. $all_file_of_directory[$language_variable] = "\"".$new_language."\";";
  29. $result_array = [];
  30. foreach ($all_file_of_directory as $key_value => $value_info) {
  31. $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
  32. }
  33. $variables_with_problems = '';
  34. if (!empty($result_array)) {
  35. foreach ($result_array as $key => $result) {
  36. if ($result == false) {
  37. $variables_with_problems .= $key.' <br />';
  38. }
  39. }
  40. }
  41. if (isset($_REQUEST['redirect'])) {
  42. $message = Display::return_message(get_lang('The new word has been added'), 'success');
  43. if (!empty($variables_with_problems)) {
  44. Display::return_message(
  45. $path_folder.' '.get_lang('is not writeable').'<br /> '.api_ucwords(get_lang('errors found'))
  46. .': <br />'.$variables_with_problems,
  47. 'error'
  48. );
  49. }
  50. Display::addFlash($message);
  51. if (isset($_REQUEST['extra_field_type'])) {
  52. $redirectUrl = api_get_path(WEB_CODE_PATH).'admin/extra_fields.php';
  53. switch ($_REQUEST['extra_field_type']) {
  54. case ExtraField::USER_FIELD_TYPE:
  55. header("Location: {$redirectUrl}?type=user");
  56. exit;
  57. case ExtraField::COURSE_FIELD_TYPE:
  58. header("Location: {$redirectUrl}?type=course");
  59. exit;
  60. case ExtraField::SESSION_FIELD_TYPE:
  61. header("Location: {$redirectUrl}?type=session");
  62. exit;
  63. }
  64. }
  65. if (isset($_REQUEST['skill'])) {
  66. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
  67. exit;
  68. }
  69. }
  70. if (!empty($variables_with_problems)) {
  71. echo $path_folder.' '.get_lang('is not writeable').'<br /> '.api_ucwords(get_lang('errors found')).': <br />'.$variables_with_problems;
  72. } else {
  73. echo 1;
  74. }
  75. }