You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
388 lines
16 KiB
388 lines
16 KiB
15 years ago
|
<?php
|
||
14 years ago
|
/* For licensing terms, see /license.txt */
|
||
13 years ago
|
/**
|
||
7 years ago
|
* Script for sub-language administration.
|
||
|
*
|
||
13 years ago
|
* @package chamilo.admin.sub_language
|
||
|
*/
|
||
15 years ago
|
$cidReset = true;
|
||
13 years ago
|
$this_script = 'sub_language';
|
||
8 years ago
|
require_once __DIR__.'/../inc/global.inc.php';
|
||
13 years ago
|
$this_section = SECTION_PLATFORM_ADMIN;
|
||
15 years ago
|
|
||
|
api_protect_admin_script();
|
||
8 years ago
|
$htmlHeadXtra[] = '<script>
|
||
6 years ago
|
$(function () {
|
||
8 years ago
|
$(".save").click(function() {
|
||
|
var button_name=$(this).attr("name");
|
||
|
var button_array=button_name.split("|");
|
||
|
var button_name=button_array[1];
|
||
|
var file_id=button_array[2];
|
||
|
var is_variable_language="$"+button_name;
|
||
10 years ago
|
|
||
8 years ago
|
var is_new_language = $("#txtid_"+file_id+"_"+button_name).val();
|
||
|
if (is_new_language == undefined) {
|
||
|
is_new_language="_";
|
||
|
}
|
||
|
if (is_new_language.length>0 && is_new_language!="_" && file_id!="" && button_name!="") {
|
||
|
$.ajax({
|
||
|
contentType: "application/x-www-form-urlencoded",
|
||
6 years ago
|
beforeSend: function(myObject) {
|
||
8 years ago
|
$("#div_message_information_id").html("<div class=\"alert alert-info\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
|
||
|
},
|
||
|
type: "POST",
|
||
|
url: "../admin/sub_language_ajax.inc.php",
|
||
|
data: {
|
||
|
\'new_language\': is_new_language,
|
||
|
\'variable_language\': is_variable_language,
|
||
|
\'file_id\': file_id,
|
||
7 years ago
|
\'id\': '.intval($_REQUEST['id']).',
|
||
|
\'sub\': '.intval($_REQUEST['sub_language_id']).',
|
||
|
\'sub_language_id\': '.intval($_REQUEST['sub_language_id']).'
|
||
8 years ago
|
},
|
||
|
success: function(datos) {
|
||
|
if (datos == "1") {
|
||
5 years ago
|
$("#div_message_information_id").html(\''.Display::return_message(get_lang('The new word has been added'), 'success').'\');
|
||
8 years ago
|
} else {
|
||
|
$("#div_message_information_id").html("<div class=\"alert alert-warning\">" + datos +"</div>");
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
5 years ago
|
$("#div_message_information_id").html(\''.Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error').'\');
|
||
8 years ago
|
}
|
||
|
});
|
||
10 years ago
|
});
|
||
15 years ago
|
</script>';
|
||
8 years ago
|
|
||
13 years ago
|
/**
|
||
7 years ago
|
* Main code.
|
||
13 years ago
|
*/
|
||
15 years ago
|
// setting the name of the tool
|
||
5 years ago
|
$tool_name = get_lang('Create sub-language');
|
||
15 years ago
|
// setting breadcrumbs
|
||
5 years ago
|
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
|
||
|
$interbreadcrumb[] = ['url' => 'languages.php', 'name' => get_lang('Chamilo Portal Languages')];
|
||
15 years ago
|
|
||
14 years ago
|
$sublanguage_folder_error = false;
|
||
|
|
||
8 years ago
|
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
|
||
8 years ago
|
$language_name = SubLanguageManager::get_name_of_language_by_id($_GET['id']);
|
||
|
$sub_language_name = SubLanguageManager::get_name_of_language_by_id($_GET['sub_language_id']);
|
||
8 years ago
|
$all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
|
||
|
$all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
|
||
|
$sub_language_file = api_get_path(SYS_LANG_PATH).$all_data_of_sublanguage['dokeos_folder'];
|
||
10 years ago
|
|
||
8 years ago
|
if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
|
||
5 years ago
|
$sublanguage_folder_error = $sub_language_file.' '.get_lang('is not writeable');
|
||
8 years ago
|
}
|
||
8 years ago
|
if (SubLanguageManager::check_if_exist_language_by_id($_GET['id']) === true) {
|
||
8 years ago
|
$language_id_exist = true;
|
||
|
} else {
|
||
|
$language_id_exist = false;
|
||
|
}
|
||
15 years ago
|
} else {
|
||
8 years ago
|
$language_name = '';
|
||
|
$language_id_exist = false;
|
||
15 years ago
|
}
|
||
|
|
||
5 years ago
|
$intro = sprintf(get_lang('Define new terms for sub-language %s by searching some term, then save each translation by clicking the save button. You will then have to switch your own user language to see the new terms appear.'), strtolower($sub_language_name));
|
||
13 years ago
|
$path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'];
|
||
|
|
||
8 years ago
|
if (!is_dir($path_folder) || strlen($all_data_of_language['dokeos_folder']) == 0) {
|
||
8 years ago
|
api_not_allowed(true);
|
||
15 years ago
|
}
|
||
|
|
||
|
Display :: display_header($language_name);
|
||
|
|
||
|
echo '<div class="actions-message" >';
|
||
9 years ago
|
echo $intro;
|
||
|
echo '<br />';
|
||
5 years ago
|
printf(get_lang('Parent language: %s'), $language_name);
|
||
15 years ago
|
echo '</div>';
|
||
8 years ago
|
echo '<br />';
|
||
9 years ago
|
$txt_search_word = (!empty($_REQUEST['txt_search_word']) ? Security::remove_XSS($_REQUEST['txt_search_word']) : '');
|
||
8 years ago
|
$html = '<div style="float:left" class="actions">';
|
||
|
$html .= '<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="GET" action="sub_language.php">';
|
||
5 years ago
|
$html .= ' '.get_lang('Original name').' : ';
|
||
15 years ago
|
|
||
8 years ago
|
$html .= '<input name="id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['id']).'" />';
|
||
|
$html .= '<input name="sub_language_id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['sub_language_id']).'" />';
|
||
|
$html .= '<input name="txt_search_word" type="text" size="50" id="txt_search_word" value="'.$txt_search_word.'" />';
|
||
|
$html .= " ".'<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
|
||
|
$html .= '</form>';
|
||
|
$html .= '</div>';
|
||
15 years ago
|
echo $html;
|
||
14 years ago
|
echo '<br /><br /><br />';
|
||
|
if (!empty($sublanguage_folder_error)) {
|
||
8 years ago
|
echo Display::return_message($sublanguage_folder_error, 'warning');
|
||
14 years ago
|
}
|
||
15 years ago
|
echo '<div id="div_message_information_id"> </div>';
|
||
|
|
||
|
/**
|
||
9 years ago
|
* @param $term The term to search
|
||
7 years ago
|
* @param bool $search_in_variable The search will include the variable definition of the term
|
||
|
* @param bool $search_in_english The search will include the english language variables
|
||
|
* @param bool $search_in_parent The search will include the parent language variables of the sub language
|
||
9 years ago
|
* @param bool $search_in_sub_language The search will include the sub language variables
|
||
7 years ago
|
*
|
||
15 years ago
|
* @author Julio Montoya
|
||
7 years ago
|
*
|
||
9 years ago
|
* @return array
|
||
15 years ago
|
*/
|
||
10 years ago
|
function search_language_term(
|
||
8 years ago
|
$term,
|
||
|
$search_in_variable = true,
|
||
|
$search_in_english = true,
|
||
|
$search_in_parent = true,
|
||
|
$search_in_sub_language = true
|
||
10 years ago
|
) {
|
||
8 years ago
|
//These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION)
|
||
|
/*
|
||
|
These 4 arrays are set in global.inc.php with the condition that will be load from sub_language.php or sub_language_ajax.inc.php
|
||
|
$english_language_array
|
||
|
$parent_language_array
|
||
|
$sub_language_array
|
||
|
$language_files_to_load
|
||
|
*/
|
||
|
global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array;
|
||
|
$language_files_to_load_keys = array_flip($language_files_to_load);
|
||
|
$array_to_search = $parent_language_array;
|
||
7 years ago
|
$list_info = [];
|
||
8 years ago
|
$term = '/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
|
||
8 years ago
|
//@todo optimize this foreach
|
||
|
foreach ($language_files_to_load as $lang_file) {
|
||
|
//searching in parent language of the sub language
|
||
|
if ($search_in_parent) {
|
||
|
$variables = $parent_language_array[$lang_file];
|
||
|
foreach ($variables as $parent_name_variable => $parent_variable_value) {
|
||
|
//arrays are avoided
|
||
|
if (is_array($parent_variable_value)) {
|
||
|
continue;
|
||
|
}
|
||
|
$founded = false;
|
||
|
// searching the item in the parent tool
|
||
|
if (preg_match($term, $parent_variable_value) !== 0) {
|
||
|
$founded = true;
|
||
|
}
|
||
|
if ($founded) {
|
||
|
//loading variable from the english array
|
||
7 years ago
|
$sub_language_name_variable = isset($sub_language_array[$lang_file][$parent_name_variable])
|
||
|
? $sub_language_array[$lang_file][$parent_name_variable]
|
||
|
: '';
|
||
8 years ago
|
//loading variable from the english array
|
||
|
$english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
|
||
15 years ago
|
|
||
8 years ago
|
//config buttons
|
||
|
/*if (strlen($english_name_variable)>1500) {
|
||
|
$size =20;
|
||
|
} else {
|
||
|
$size =4;
|
||
|
}*/
|
||
15 years ago
|
|
||
7 years ago
|
$obj_text = Display::tag(
|
||
|
'textarea',
|
||
|
$sub_language_name_variable,
|
||
|
[
|
||
|
'rows' => 10,
|
||
|
'cols' => 40,
|
||
|
'name' => 'txt|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
'id' => 'txtid_'.$language_files_to_load_keys[$lang_file].'_'.$parent_name_variable,
|
||
|
]
|
||
|
);
|
||
|
$obj_button = Display::button(
|
||
|
'btn|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
get_lang('Save'),
|
||
|
[
|
||
|
'class' => 'save btn btn-default btn-sm',
|
||
|
'type' => 'button',
|
||
|
'id' => 'btnid_'.$parent_name_variable,
|
||
|
]
|
||
|
);
|
||
15 years ago
|
|
||
7 years ago
|
$list_info[$parent_name_variable] = [
|
||
8 years ago
|
$lang_file.'.inc.php',
|
||
8 years ago
|
$parent_name_variable,
|
||
7 years ago
|
htmlentities($english_name_variable),
|
||
|
htmlentities($parent_variable_value),
|
||
8 years ago
|
$obj_text,
|
||
7 years ago
|
$obj_button,
|
||
7 years ago
|
];
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
8 years ago
|
//search in english
|
||
|
if ($search_in_english || $search_in_variable) {
|
||
|
$variables = $english_language_array[$lang_file];
|
||
|
foreach ($variables as $name_variable => $variable_value) {
|
||
7 years ago
|
if (isset($list_info[$name_variable])) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
8 years ago
|
if (is_array($variable_value)) {
|
||
|
continue;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (is_array($variable_value)) {
|
||
|
echo $lang_file;
|
||
|
}
|
||
|
$founded = false;
|
||
|
if ($search_in_english && $search_in_variable) {
|
||
|
// searching the item in the parent tool
|
||
|
if (preg_match($term, $variable_value) !== 0 || preg_match($term, $name_variable) !== 0) {
|
||
|
$founded = true;
|
||
|
}
|
||
|
} else {
|
||
|
if ($search_in_english) {
|
||
|
if (preg_match($term, $variable_value) !== 0) {
|
||
|
$founded = true;
|
||
|
}
|
||
|
} else {
|
||
|
if (preg_match($term, $name_variable) !== 0) {
|
||
|
$founded = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
8 years ago
|
if ($founded) {
|
||
|
//loading variable from the english array
|
||
|
$sub_language_name_variable = null;
|
||
|
if (isset($sub_language_array[$lang_file][$name_variable])) {
|
||
|
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
|
||
|
}
|
||
|
$parent_variable_value = null;
|
||
|
if (isset($parent_language_array[$lang_file][$name_variable])) {
|
||
|
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
|
||
|
}
|
||
|
//config buttons
|
||
7 years ago
|
$obj_text = Display::tag(
|
||
|
'textarea',
|
||
|
$sub_language_name_variable,
|
||
|
[
|
||
|
'rows' => 10,
|
||
|
'cols' => 40,
|
||
|
'name' => 'txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
'id' => 'txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable,
|
||
|
]
|
||
|
);
|
||
|
$obj_button = Display::button(
|
||
|
'btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
get_lang('Save'),
|
||
|
[
|
||
|
'class' => 'save btn btn-default btn-sm',
|
||
|
'type' => 'button',
|
||
|
'id' => 'btnid_'.$name_variable,
|
||
|
]
|
||
|
);
|
||
15 years ago
|
|
||
8 years ago
|
//loading variable from the english array
|
||
|
$english_name_variable = $english_language_array[$lang_file][$name_variable];
|
||
15 years ago
|
|
||
7 years ago
|
$list_info[] = [
|
||
8 years ago
|
$lang_file.'.inc.php',
|
||
8 years ago
|
$name_variable,
|
||
7 years ago
|
htmlentities($english_name_variable),
|
||
|
htmlentities($parent_variable_value),
|
||
8 years ago
|
$obj_text,
|
||
7 years ago
|
$obj_button,
|
||
7 years ago
|
];
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
8 years ago
|
// Search in sub language
|
||
|
if ($search_in_sub_language) {
|
||
|
$variables = $sub_language_array[$lang_file];
|
||
|
foreach ($variables as $name_variable => $variable_value) {
|
||
|
if (is_array($parent_variable_value)) {
|
||
|
continue;
|
||
|
}
|
||
15 years ago
|
|
||
8 years ago
|
if (is_array($variable_value)) {
|
||
|
continue;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
$founded = false;
|
||
|
// searching the item in the parent tool
|
||
|
if (preg_match($term, $variable_value) !== 0) {
|
||
|
$founded = true;
|
||
|
}
|
||
|
if ($founded) {
|
||
|
//loading variable from the english array
|
||
7 years ago
|
$sub_language_name_variable = isset($sub_language_array[$lang_file][$name_variable])
|
||
|
? $sub_language_array[$lang_file][$name_variable]
|
||
|
: '';
|
||
|
$parent_variable_value = isset($parent_language_array[$lang_file][$name_variable])
|
||
|
? $parent_language_array[$lang_file][$name_variable]
|
||
|
: '';
|
||
8 years ago
|
//config buttons
|
||
7 years ago
|
$obj_text = Display::tag(
|
||
|
'textarea',
|
||
|
$sub_language_name_variable,
|
||
|
[
|
||
|
'rows' => 10,
|
||
|
'cols' => 40,
|
||
|
'name' => 'txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
'id' => 'txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable,
|
||
|
]
|
||
|
);
|
||
|
$obj_button = Display::button(
|
||
|
'btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file],
|
||
|
get_lang('Save'),
|
||
|
[
|
||
|
'class' => 'save btn btn-default btn-sm',
|
||
|
'type' => 'button',
|
||
|
'id' => 'btnid_'.$name_variable,
|
||
|
]
|
||
|
);
|
||
15 years ago
|
|
||
8 years ago
|
//loading variable from the english array
|
||
|
$english_name_variable = $english_language_array[$lang_file][$name_variable];
|
||
7 years ago
|
$list_info[] = [$lang_file.'.inc.php',
|
||
8 years ago
|
$name_variable,
|
||
|
$english_name_variable,
|
||
7 years ago
|
$parent_variable_value, $obj_text, $obj_button, ];
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
8 years ago
|
$list_info = array_unique_dimensional($list_info);
|
||
7 years ago
|
|
||
8 years ago
|
return $list_info;
|
||
15 years ago
|
}
|
||
10 years ago
|
|
||
|
// Allow see data in sort table
|
||
7 years ago
|
$list_info = [];
|
||
15 years ago
|
if (isset($_REQUEST['txt_search_word'])) {
|
||
8 years ago
|
//@todo fix to accept a char with 1 char
|
||
8 years ago
|
if (strlen(trim($_REQUEST['txt_search_word'])) > 2) {
|
||
8 years ago
|
$list_info = search_language_term(
|
||
|
$_REQUEST['txt_search_word'],
|
||
|
true,
|
||
|
true,
|
||
|
true,
|
||
|
true
|
||
|
);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
7 years ago
|
$parameters = [
|
||
8 years ago
|
'id' => intval($_GET['id']),
|
||
|
'sub_language_id' => intval($_GET['sub_language_id']),
|
||
7 years ago
|
'txt_search_word' => $txt_search_word,
|
||
7 years ago
|
];
|
||
8 years ago
|
$table = new SortableTableFromArrayConfig($list_info, 1, 20, 'data_info');
|
||
15 years ago
|
$table->set_additional_parameters($parameters);
|
||
5 years ago
|
$table->set_header(0, get_lang('Language file'));
|
||
|
$table->set_header(1, get_lang('Language variable'));
|
||
|
$table->set_header(2, get_lang('English name'));
|
||
|
$table->set_header(3, get_lang('Original name'));
|
||
8 years ago
|
$table->set_header(4, get_lang('Translation'), false);
|
||
|
$table->set_header(5, get_lang('Action'), false);
|
||
7 years ago
|
$table->setHideColumn(0);
|
||
15 years ago
|
$table->display();
|
||
|
|
||
13 years ago
|
Display :: display_footer();
|