sub_language_ajax.inc.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /**
  8. * Init
  9. */
  10. $language_file = 'admin';
  11. $this_script = 'sub_language';
  12. require_once '../inc/global.inc.php';
  13. require_once 'sub_language.class.php';
  14. api_protect_admin_script();
  15. $new_language = Security::remove_XSS($_REQUEST['new_language']);
  16. $language_variable = Security::remove_XSS($_REQUEST['variable_language']);
  17. $file_id = intval($_REQUEST['file_id']);
  18. /**
  19. * Code
  20. */
  21. if (isset($new_language) && isset($language_variable) && isset($file_id)) {
  22. $file_language = $language_files_to_load[$file_id].'.inc.php';
  23. $id_language = intval($_REQUEST['id']);
  24. $sub_language_id = intval($_REQUEST['sub']);
  25. $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id);
  26. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'].'/'.$file_language;
  27. $all_file_of_directory = SubLanguageManager::get_all_language_variable_in_file($path_folder);
  28. $return_value = SubLanguageManager::add_file_in_language_directory($path_folder);
  29. //update variable language
  30. // Replace double quotes to avoid parse errors
  31. $new_language = str_replace('"', '\"',$new_language);
  32. // Replace new line signs to avoid parse errors - see #6773
  33. $new_language = str_replace("\n","\\n",$new_language);
  34. $all_file_of_directory[$language_variable]="\"".api_convert_encoding($new_language, api_get_system_encoding(),'UTF-8')."\";";
  35. $result_array = array();
  36. foreach ($all_file_of_directory as $key_value=>$value_info) {
  37. $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
  38. }
  39. $variables_with_problems = '';
  40. if (!empty($result_array)) {
  41. foreach ($result_array as $key => $result) {
  42. if ($result == false) {
  43. $variables_with_problems .=$key.' <br />';
  44. }
  45. }
  46. }
  47. if (!empty($variables_with_problems)) {
  48. echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
  49. } else {
  50. echo get_lang('Saved');
  51. }
  52. }