1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | use Chamilo\CoreBundle\Entity\ExtraField; |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | /** |
||
7 | * Sub language AJAX script to update variables. |
||
8 | * |
||
9 | * @package chamilo.admin.sub_language |
||
10 | */ |
||
11 | $this_script = 'sub_language'; |
||
12 | require_once __DIR__.'/../inc/global.inc.php'; |
||
13 | |||
14 | api_protect_admin_script(); |
||
15 | |||
16 | $new_language = Security::remove_XSS($_REQUEST['new_language']); |
||
17 | $language_variable = Security::remove_XSS($_REQUEST['variable_language']); |
||
18 | $file_id = intval($_REQUEST['file_id']); |
||
19 | |||
20 | if (isset($new_language) && isset($language_variable) && isset($file_id)) { |
||
21 | $file_language = $language_files_to_load[$file_id].'.inc.php'; |
||
22 | $id_language = intval($_REQUEST['id']); |
||
23 | $sub_language_id = intval($_REQUEST['sub']); |
||
24 | $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id); |
||
25 | |||
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 | |||
30 | //update variable language |
||
31 | // Replace double quotes to avoid parse errors |
||
32 | $new_language = str_replace('"', '\"', $new_language); |
||
33 | // Replace new line signs to avoid parse errors - see #6773 |
||
34 | $new_language = str_replace("\n", "\\n", $new_language); |
||
35 | $all_file_of_directory[$language_variable] = "\"".$new_language."\";"; |
||
36 | $result_array = []; |
||
37 | |||
38 | foreach ($all_file_of_directory as $key_value => $value_info) { |
||
39 | $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value); |
||
40 | } |
||
41 | $variables_with_problems = ''; |
||
42 | if (!empty($result_array)) { |
||
43 | foreach ($result_array as $key => $result) { |
||
44 | if ($result == false) { |
||
45 | $variables_with_problems .= $key.' <br />'; |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if (isset($_REQUEST['redirect'])) { |
||
51 | $message = Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success'); |
||
52 | |||
53 | if (!empty($variables_with_problems)) { |
||
54 | Display::return_message( |
||
55 | $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')) |
||
56 | .': <br />'.$variables_with_problems, |
||
57 | 'error' |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | Display::addFlash($message); |
||
62 | |||
63 | if (isset($_REQUEST['extra_field_type'])) { |
||
64 | $redirectUrl = api_get_path(WEB_CODE_PATH).'admin/extra_fields.php'; |
||
65 | |||
66 | switch ($_REQUEST['extra_field_type']) { |
||
67 | case ExtraField::USER_FIELD_TYPE: |
||
68 | header("Location: {$redirectUrl}?type=user"); |
||
69 | exit; |
||
70 | case ExtraField::COURSE_FIELD_TYPE: |
||
71 | header("Location: {$redirectUrl}?type=course"); |
||
72 | exit; |
||
73 | case ExtraField::SESSION_FIELD_TYPE: |
||
74 | header("Location: {$redirectUrl}?type=session"); |
||
75 | exit; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | if (isset($_REQUEST['skill'])) { |
||
80 | header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php'); |
||
81 | exit; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | if (!empty($variables_with_problems)) { |
||
86 | echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems; |
||
87 | } else { |
||
88 | echo 1; |
||
89 | } |
||
90 | } |
||
91 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: