sub_language_ajax.inc.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 (!empty($variables_with_problems)) {
  43. echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
  44. } else {
  45. echo get_lang('Saved');
  46. }
  47. }