Skip to content

Commit

Permalink
Setitngs: Fix PlatformLanguage setting to support multi-URL configura…
Browse files Browse the repository at this point in the history
…tions - refs chamilo#6030
  • Loading branch information
christianbeeznest committed Jan 15, 2025
1 parent 15023ce commit b7513f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
8 changes: 6 additions & 2 deletions main/admin/languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
);
// changing the Platform language
if (isset($_POST['platformlanguage']) && $_POST['platformlanguage'] != '') {
api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, $_configuration['access_url']);
api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, api_get_current_access_url_id());
}
} elseif (isset($_POST['action'])) {
switch ($_POST['action']) {
Expand Down Expand Up @@ -263,7 +263,11 @@
$sql_select = "SELECT * FROM $tbl_admin_languages";
$result_select = Database::query($sql_select);

$sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
$current_access_url = api_get_current_access_url_id();
$sql_select_lang = "SELECT * FROM $tbl_settings_current
WHERE category='Languages'
AND access_url = $current_access_url";

$result_select_lang = Database::query($sql_select_lang);
$row_lang = Database::fetch_array($result_select_lang);

Expand Down
48 changes: 30 additions & 18 deletions main/inc/lib/sub_language.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,32 +427,44 @@ public static function make_available_language($language_id)
/**
* Set platform language.
*
* @param int $language_id The language id
* @param int $languageId The language id
*
* @return bool
*/
public static function set_platform_language($language_id)
public static function set_platform_language($languageId)
{
if (empty($language_id) || (intval($language_id) != $language_id)) {
if (empty($languageId) || intval($languageId) != $languageId) {
return false;
}
$language_id = intval($language_id);
$tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE);
$tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql = "SELECT english_name FROM $tbl_admin_languages
WHERE id = $language_id";

$languageId = intval($languageId);
$tblAdminLanguages = Database::get_main_table(TABLE_MAIN_LANGUAGE);

$sql = "SELECT english_name FROM $tblAdminLanguages WHERE id = $languageId";
$result = Database::query($sql);
$lang = Database::fetch_array($result);
$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value = '".$lang['english_name']."'
WHERE variable='platformLanguage'";
$result_2 = Database::query($sql_update_2);
Event::addEvent(
LOG_PLATFORM_LANGUAGE_CHANGE,
LOG_PLATFORM_LANGUAGE,
$lang['english_name']
);

return $result_2 !== false;

if ($lang) {
$success = api_set_setting(
'platformLanguage',
$lang['english_name'],
null,
null,
api_get_current_access_url_id()
);

if ($success) {
Event::addEvent(
LOG_PLATFORM_LANGUAGE_CHANGE,
LOG_PLATFORM_LANGUAGE,
$lang['english_name']
);
}

return $success;
}

return false;
}

/**
Expand Down

0 comments on commit b7513f2

Please sign in to comment.