sub_language_ajax.inc.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @package chamilo.admin.sub_language
  7. */
  8. $this_script = 'sub_language';
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_protect_admin_script();
  11. $new_language = Security::remove_XSS($_REQUEST['new_language']);
  12. $language_variable = Security::remove_XSS($_REQUEST['variable_language']);
  13. $file_id = intval($_REQUEST['file_id']);
  14. /**
  15. * Code
  16. */
  17. if (isset($new_language) && isset($language_variable) && isset($file_id)) {
  18. $file_language = $language_files_to_load[$file_id].'.inc.php';
  19. $id_language = intval($_REQUEST['id']);
  20. $sub_language_id = intval($_REQUEST['sub']);
  21. $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id);
  22. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'].'/'.$file_language;
  23. $all_file_of_directory = SubLanguageManager::get_all_language_variable_in_file($path_folder);
  24. $return_value = SubLanguageManager::add_file_in_language_directory($path_folder);
  25. //update variable language
  26. // Replace double quotes to avoid parse errors
  27. $new_language = str_replace('"', '\"', $new_language);
  28. // Replace new line signs to avoid parse errors - see #6773
  29. $new_language = str_replace("\n", "\\n", $new_language);
  30. $all_file_of_directory[$language_variable] = "\"".$new_language."\";";
  31. $result_array = array();
  32. foreach ($all_file_of_directory as $key_value=>$value_info) {
  33. $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
  34. }
  35. $variables_with_problems = '';
  36. if (!empty($result_array)) {
  37. foreach ($result_array as $key => $result) {
  38. if ($result == false) {
  39. $variables_with_problems .= $key.' <br />';
  40. }
  41. }
  42. }
  43. if (isset($_REQUEST['redirect'], $_REQUEST['extra_field_type'])) {
  44. Display::addFlash(
  45. Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success')
  46. );
  47. $redirectUrl = api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=';
  48. switch ($_REQUEST['extra_field_type']) {
  49. case ExtraField::USER_FIELD_TYPE:
  50. $redirectUrl .= 'user';
  51. break;
  52. case ExtraField::COURSE_FIELD_TYPE:
  53. $redirectUrl .= 'course';
  54. break;
  55. case ExtraField::SESSION_FIELD_TYPE:
  56. $redirectUrl .= 'session';
  57. break;
  58. }
  59. header("Location: $redirectUrl");
  60. exit;
  61. }
  62. if (!empty($variables_with_problems)) {
  63. echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
  64. } else {
  65. echo 1;
  66. }
  67. }