sub_language_ajax.inc.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $new_language = str_replace('"', '\"',$new_language);
  31. $all_file_of_directory[$language_variable]="\"".api_convert_encoding($new_language, api_get_system_encoding(),'UTF-8')."\";";
  32. $result_array = array();
  33. foreach ($all_file_of_directory as $key_value=>$value_info) {
  34. $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
  35. }
  36. $variables_with_problems = '';
  37. if (!empty($result_array)) {
  38. foreach($result_array as $key =>$result) {
  39. if ($result == false) {
  40. $variables_with_problems .=$key.' <br />';
  41. }
  42. }
  43. }
  44. if (!empty($variables_with_problems)) {
  45. echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
  46. } else {
  47. echo get_lang('Saved');
  48. }
  49. }