sub_language_ajax.inc.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Sub language AJAX script to update variables
  5. * @package chamilo.admin.sub_language
  6. */
  7. $this_script = 'sub_language';
  8. //require_once '../inc/global.inc.php';
  9. api_protect_admin_script();
  10. $new_language = Security::remove_XSS($_REQUEST['new_language']);
  11. $language_variable = Security::remove_XSS($_REQUEST['variable_language']);
  12. $file_id = intval($_REQUEST['file_id']);
  13. /**
  14. * Code
  15. */
  16. if (isset($new_language) && isset($language_variable) && isset($file_id)) {
  17. $file_language = $language_files_to_load[$file_id].'.inc.php';
  18. $id_language = intval($_REQUEST['id']);
  19. $sub_language_id = intval($_REQUEST['sub']);
  20. $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id);
  21. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'].'/'.$file_language;
  22. $all_file_of_directory = SubLanguageManager::get_all_language_variable_in_file($path_folder);
  23. $return_value = SubLanguageManager::add_file_in_language_directory($path_folder);
  24. //update variable language
  25. // Replace double quotes to avoid parse errors
  26. $new_language = str_replace('"', '\"',$new_language);
  27. // Replace new line signs to avoid parse errors - see #6773
  28. $new_language = str_replace("\n","\\n",$new_language);
  29. $all_file_of_directory[$language_variable]="\"".$new_language."\";";
  30. $result_array = array();
  31. foreach ($all_file_of_directory as $key_value=>$value_info) {
  32. $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
  33. }
  34. $variables_with_problems = '';
  35. if (!empty($result_array)) {
  36. foreach ($result_array as $key => $result) {
  37. if ($result == false) {
  38. $variables_with_problems .=$key.' <br />';
  39. }
  40. }
  41. }
  42. if (isset($_REQUEST['redirect'])) {
  43. Display::addFlash(
  44. Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success')
  45. );
  46. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'admin/sub_language.php?' . http_build_query([
  47. 'id' => $id_language,
  48. 'sub_language_id' => $sub_language_id,
  49. 'txt_search_word' => ltrim($language_variable, '$')
  50. ]));
  51. exit;
  52. }
  53. if (!empty($variables_with_problems)) {
  54. echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
  55. } else {
  56. echo 1;
  57. }
  58. }