Now you can't disable the current platform language + when disabling a language that is used by users, the system will ask if you want to set the default platform language to all users instead of the disabled language see #3877

skala
Julio Montoya 13 years ago
parent 6b4ee0e698
commit 9efd3b52a9
  1. 81
      main/admin/languages.php
  2. 84
      main/admin/sub_language.class.php
  3. 11
      main/inc/lib/usermanager.lib.php

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This page allows the platform admin to decide which languages should
@ -23,7 +24,6 @@ $cidReset = true;
// include global script
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'sortable_table.class.php';
require_once 'sub_language.class.php';
$this_section = SECTION_PLATFORM_ADMIN;
@ -33,8 +33,12 @@ api_protect_admin_script();
if (isset($_POST['sent_http_request'])) {
if (isset($_POST['visibility']) && $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 0) {
if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
if (SubLanguageManager::check_if_language_is_used($_POST['id']) == false) {
SubLanguageManager::make_unavailable_language($_POST['id']);
echo 'set_hidden';
} else {
echo 'confirm:' . intval($_POST['id']);
}
}
}
if (isset($_POST['visibility']) && $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 1) {
@ -45,7 +49,9 @@ if (isset($_POST['sent_http_request'])) {
}
exit;
}
$htmlHeadXtra[] ='<script type="text/javascript">
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
//$(window).load(function () {
@ -76,14 +82,14 @@ $htmlHeadXtra[] ='<script type="text/javascript">
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("#id_content_message").html("<div class=\"normal-message\"><img src='.api_get_path(WEB_PATH).'main/inc/lib/javascript/indicator.gif\' /></div>");
$("#id_content_message").html("<div class=\"normal-message\"><img src=\"' . api_get_path(WEB_PATH) . 'main/img/loading1.gif\" /></div>");
},
type: "POST",
url: "../admin/languages.php",
data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
success: function(datos) {
if (datos=="set_visible" || datos=="set_hidden") {
$("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
if (my_image_tool=="visible.png") {
@ -96,12 +102,20 @@ $htmlHeadXtra[] ='<script type="text/javascript">
if (datos=="set_visible") {
$("#id_content_message").html("<div class=\"confirmation-message\">' . get_lang('LanguageIsNowVisible', '') . '</div>");
} else {
}
if (datos=="set_hidden") {
$("#id_content_message").html("<div class=\"confirmation-message\">' . get_lang('LanguageIsNowHidden', '') . '</div>");
}
}
var action = datos.split(":")[0];
if (action && action == "confirm") {
var id = datos.split(":")[1];
var sure = "<div class=\"warning-message\">'.get_lang('ThereAreUsersUsingThisLanguageYouWantToDisableThisLanguageAndSetTheUserWithTheDefaultPortalLanguage').'</div><a href=\"languages.php?action=make_unavailable_confirmed&id="+id+"\" class=\"btn\">' . get_lang('MakeUnavailable') . '</a>";
$("#id_content_message").html(sure);
}
} });
});
});
@ -118,49 +132,38 @@ $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT)
// we change the availability
if ($_GET['action'] == 'makeunavailable') {
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
SubLanguageManager::make_unavailable_language($_GET['id']);
}
}
if ($_GET['action'] == 'makeavailable') {
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
SubLanguageManager::make_available_language($_GET['id']);
}
}
if ($_GET['action'] == 'setplatformlanguage') {
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
SubLanguageManager::set_platform_language($_GET['id']);
}
}
if ($_POST['Submit'])
{
if ($_POST['Submit']) {
// changing the name
$sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
$result = Database::query($sql_update);
// changing the Platform language
if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
{
if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '') {
//$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
//$result_2 = Database::query($sql_update_2);
api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, $_configuration['access_url']);
}
}
elseif (isset($_POST['action']))
{
switch ($_POST['action'])
{
} elseif (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'makeavailable' :
if (count($_POST['id']) > 0)
{
if (count($_POST['id']) > 0) {
$ids = array();
foreach ($_POST['id'] as $index => $id)
{
foreach ($_POST['id'] as $index => $id) {
$ids[] = Database::escape_string($id);
}
$sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('" . implode("','", $ids) . "')";
@ -168,11 +171,9 @@ elseif (isset($_POST['action']))
}
break;
case 'makeunavailable' :
if (count($_POST['id']) > 0)
{
if (count($_POST['id']) > 0) {
$ids = array();
foreach ($_POST['id'] as $index => $id)
{
foreach ($_POST['id'] as $index => $id) {
$ids[] = Database::escape_string($id);
}
$sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('" . implode("','", $ids) . "')";
@ -197,11 +198,18 @@ $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAd
// including the header file (which includes the banner itself)
Display :: display_header($tool_name);
// displaying the naam of the tool
//api_display_tool_title($tool_name);
if (isset($_GET['action']) && $_GET['action'] == 'make_unavailable_confirmed') {
$language_info = SubLanguageManager::get_all_information_of_language($_GET['id']);
if ($language_info['available'] == 1) {
SubLanguageManager::make_unavailable_language($_GET['id']);
$platform_language = api_get_setting('platformLanguage');
UserManager::update_all_user_languages($language_info['english_name'], $platform_language);
Display::display_confirmation_message(get_lang('LanguageIsNowHidden'));
}
}
// displaying the explanation for this tool
echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
Display::display_normal_message(get_lang('PlatformLanguagesExplanation'));
// selecting all the languages
$sql_select = "SELECT * FROM $tbl_admin_languages";
@ -234,8 +242,10 @@ while ($row = Database::fetch_array($result_select)) {
} else {
$row_td[] = $row['original_name'];
}
// the second column
$row_td[] = $row['english_name'];
// the third column
$row_td[] = $row['dokeos_folder'];
@ -244,6 +254,7 @@ while ($row = Database::fetch_array($result_select)) {
} else {
$setplatformlanguage = "<a href=\"javascript:if (confirm('" . addslashes(get_lang('AreYouSureYouWantToSetThisLanguageAsThePortalDefault')) . "')) { location.href='" . api_get_self() . "?action=setplatformlanguage&id=" . $row['id'] . "'; }\">" . Display::return_icon('languages_na.png', get_lang('SetLanguageAsDefault'), '', ICON_SIZE_SMALL) . "</a>";
}
if (api_get_setting('allow_use_sub_language') == 'true') {
$verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
@ -263,19 +274,21 @@ while ($row = Database::fetch_array($result_select)) {
$allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=" . Security::remove_XSS($all_information_of_sub_language['parent_id']) . "&sub_language_id=" . Security::remove_XSS($row['id']) . "'>" . Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'), array('width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
$allow_delete_sub_language = "&nbsp;<a href='sub_language_add.php?action=deletesublanguage&id=" . Security::remove_XSS($all_information_of_sub_language['parent_id']) . "&sub_language_id=" . Security::remove_XSS($row['id']) . "'>" . Display::return_icon('delete.png', get_lang('DeleteSubLanguage'), array('width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
}
} else {
$allow_use_sub_language = '';
$allow_add_term_sub_language = '';
}
if ($row['english_name'] == $row_lang['selected_value']) {
$row_td[] = Display::return_icon('visible.png', get_lang('Visible'))."<a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>
&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
} else {
if ($row['available'] == 1) {
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_" . $row['id'] . "\" href='" . api_get_self() . "?action=makeunavailable&id=" . $row['id'] . "'>" . Display::return_icon('visible.png', get_lang('MakeUnavailable'), array('id' => 'imglinktool_' . $row['id']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
//$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('visible.gif', get_lang('MakeUnavailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
} else {
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_" . $row['id'] . "\" href='" . api_get_self() . "?action=makeavailable&id=" . $row['id'] . "'>" . Display::return_icon('invisible.png', get_lang('MakeAvailable'), array('id' => 'imglinktool_' . $row['id']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
//$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('invisible.gif', get_lang('MakeAvailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
}
}
$language_data[] = $row_td;
}

@ -1,15 +1,18 @@
<?php /* For licensing terms, see /license.txt */
<?php
/* For licensing terms, see /license.txt */
/**
* SubLanguageManager class definition file
* @package chamilo.admin.sublanguage
* @todo clean this lib and move to main/inc/lib
*/
class SubLanguageManager {
private function __construct() {
//void
}
/**
* Get all files of lang folder (forum.inc.php,gradebook.inc.php,notebook.inc.php)
* @param String The lang path folder (/var/www/my_lms/main/lang/spanish)
@ -30,14 +33,13 @@ class SubLanguageManager {
$content_dir[] = $file;
}
}
}
}
closedir($dh);
return $content_dir;
}
}
/**
* Get all information of sub-language
* @param Integer The parent id(Language father id)
@ -54,6 +56,7 @@ class SubLanguageManager {
}
return $all_information;
}
/**
* Get all information of language
* @param Integer The parent id(Language father id)
@ -69,6 +72,7 @@ class SubLanguageManager {
}
return $all_information;
}
/**
* Get all information of chamilo file
* @param String The chamilo path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
@ -82,9 +86,12 @@ class SubLanguageManager {
}
$info_file = file($system_path_file);
foreach ($info_file as $line) {
if (substr($line,0,1)!='$') { continue; }
if (substr($line, 0, 1) != '$') {
continue;
}
list($var, $val) = split('=', $line, 2);
$var = trim($var); $val = trim($val);
$var = trim($var);
$val = trim($val);
if ($get_as_string_index) { //remove the prefix $
$var = substr($var, 1);
}
@ -103,6 +110,7 @@ class SubLanguageManager {
$return_value = @file_put_contents($system_path_file, '<?php' . PHP_EOL);
return $return_value;
}
/**
* Write in file of sub-language
* @param String The path file (/var/www/chamilo/main/lang/spanish/gradebook.inc.php)
@ -125,17 +133,23 @@ class SubLanguageManager {
}
return $return_value;
}
/**
* Add directory for sub-language
* @param String The sub-language directory ( e.g. 'spanish_corporate' )
* @return boolean True on success, false on failure
*/
public static function add_language_directory($sub_language_dir) {
if (empty($sub_language_dir)) { return false; }
if (empty($sub_language_dir)) {
return false;
}
$dir = api_get_path(SYS_LANG_PATH) . $sub_language_dir;
if (is_dir($dir)) { return true; } //even if the dir already exists, we reach the objective of having the directory there
if (is_dir($dir)) {
return true;
} //even if the dir already exists, we reach the objective of having the directory there
return @mkdir($dir, api_get_permissions_for_new_directories());
}
/**
* Delete sub-language.
* In order to avoid deletion of main laguages, we check the existence of a parent
@ -143,14 +157,20 @@ class SubLanguageManager {
* @return bool True on success, false on error
*/
public static function remove_sub_language($parent_id, $sub_language_id) {
if (empty($parent_id) or (intval($parent_id)!=$parent_id) or empty($sub_language_id) or (intval($sub_language_id) != $sub_language_id)) { return false; }
if (empty($parent_id) or (intval($parent_id) != $parent_id) or empty($sub_language_id) or (intval($sub_language_id) != $sub_language_id)) {
return false;
}
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql = 'SELECT dokeos_folder FROM ' . $tbl_admin_languages . ' WHERE parent_id = ' . $parent_id . ' and id = ' . $sub_language_id;
$res = Database::query($sql);
if ($res === false or Database::num_rows($res)<1) { return false; }
if ($res === false or Database::num_rows($res) < 1) {
return false;
}
$row = Database::fetch_assoc($res);
$res = SubLanguageManager::remove_language_directory($row['dokeos_folder']);
if ($res === false) { return false; } //can't delete dir, so do not delete language record
if ($res === false) {
return false;
} //can't delete dir, so do not delete language record
$sql = 'DELETE FROM ' . $tbl_admin_languages . ' WHERE id="' . Database::escape_string($sub_language_id) . '" ';
$res = Database::query($sql);
return $res;
@ -162,9 +182,13 @@ class SubLanguageManager {
* @return boolean True on success, false on failure
*/
public static function remove_language_directory($sub_language_dir) {
if (empty($sub_language_dir)) { return false; }
if (empty($sub_language_dir)) {
return false;
}
$dir = api_get_path(SYS_LANG_PATH) . $sub_language_dir;
if (!is_dir($dir)) { return true; } //even if the dir does not exist, we reach the objective of not having the directory there
if (!is_dir($dir)) {
return true;
} //even if the dir does not exist, we reach the objective of not having the directory there
$content = SubLanguageManager::get_lang_folder_files_list($dir);
if (count($content) > 0) {
@ -194,7 +218,8 @@ class SubLanguageManager {
return false;
}
} else {
return false;;
return false;
;
}
}
@ -212,8 +237,8 @@ class SubLanguageManager {
} else {
return '';
}
}
/**
* Verified if language is sub-language
* @param Integer The language id
@ -230,6 +255,19 @@ class SubLanguageManager {
return false;
}
}
public static function check_if_language_is_used($language_id) {
$language_info = self::get_all_information_of_language($language_id);
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$sql = 'SELECT count(*) AS count FROM ' . $user_table . ' WHERE language ="' . Database::escape_string($language_info['english_name']).'"';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0 && Database::result($rs, '0', 'count') >= 1) {
return true;
} else {
return false;
}
}
/**
* Verified if language is father of an sub-language
* @param Integer The language id
@ -246,6 +284,7 @@ class SubLanguageManager {
return false;
}
}
/**
* Make unavailable the language
* @param Integer The language id
@ -257,6 +296,7 @@ class SubLanguageManager {
$result = Database::query($sql_make_unavailable);
return $result !== false; //only return false on sql error
}
/**
* Make available the language
* @param Integer The language id
@ -268,13 +308,16 @@ class SubLanguageManager {
$result = Database::query($sql_make_available);
return $result !== false; //only return false on sql error
}
/**
* Set platform language
* @param Integer The language id
* @return void()
*/
public static function set_platform_language($language_id) {
if (empty($language_id) or (intval($language_id)!=$language_id)) { return false; }
if (empty($language_id) or (intval($language_id) != $language_id)) {
return false;
}
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql_update = "SELECT english_name FROM " . $tbl_admin_languages . " WHERE id='" . Database::escape_string($language_id) . "'";
@ -285,6 +328,7 @@ class SubLanguageManager {
event_system(LOG_PLATFORM_LANGUAGE_CHANGE, LOG_PLATFORM_LANGUAGE, $lang['english_name']);
return $result_2 !== false;
}
/**
* Get platform language ID
* @return int The platform language ID
@ -294,15 +338,19 @@ class SubLanguageManager {
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql = "SELECT id FROM " . $tbl_admin_languages . " WHERE english_name ='$name'";
$res = Database::query($sql);
if (Database::num_rows($res)<1) { return false;}
if (Database::num_rows($res) < 1) {
return false;
}
$row = Database::fetch_array($res);
return $row['id'];
}
/*
* Get parent language path (or null if no parent)
* @param string Children language path
* @return string Parent language path or null
*/
public static function get_parent_language_path($language_path) {
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -314,5 +362,5 @@ class SubLanguageManager {
$row = Database::fetch_array($result);
return $row['dokeos_folder'];
}
}
?>

@ -3707,4 +3707,15 @@ EOF;
Database::query($sql);
}
}
static function update_all_user_languages($from, $to) {
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$from = Database::escape_string($from);
$to = Database::escape_string($to);
if (!empty($to) && !empty($from)) {
$sql = "UPDATE $table_user SET language = '$to' WHERE language = '$from'";
Database::query($sql);
}
}
}

Loading…
Cancel
Save