Improvements in search terms of language see DT#5130 requires testing!

skala
Julio Montoya 16 years ago
parent 79a56c20ba
commit 74f33560d8
  1. 27
      main/admin/add_by_ajax_sub_language.inc.php
  2. 10
      main/admin/languages.php
  3. 297
      main/admin/register_sub_language.php
  4. 31
      main/admin/sub_language.class.php
  5. 285
      main/admin/sub_language.php
  6. 9
      main/admin/sub_language_add.php
  7. 30
      main/admin/sub_language_ajax.inc.php
  8. 63
      main/inc/global.inc.php

@ -1,27 +0,0 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
// including the global dokeos file
require_once '../inc/global.inc.php';
require_once 'sub_language.class.php';
/*
* search a term and return description from a glossary
*/
global $charset;
$new_language = Security::remove_XSS($_POST['new_language']);
$language_variable = Security::remove_XSS($_POST['variable_language']);
$file_language = Security::remove_XSS($_POST['file_language']);
$id_language = Security::remove_XSS($_POST['id']);
$sub_language_id = Security::remove_XSS($_POST['sublanguage_id']);
$all_data_of_language=SubLanguageManager::get_all_information_of_sub_language($id_language,$sub_language_id);
$dokeos_path_folder=api_get_path('SYS_LANG_PATH').$all_data_of_language['dokeos_folder'].'/'.$file_language;
$all_file_of_directory=SubLanguageManager::get_all_language_variable_in_file($dokeos_path_folder);
SubLanguageManager::add_file_in_language_directory ($dokeos_path_folder);
//update variable language
$all_file_of_directory[$language_variable]="\"".mb_convert_encoding($new_language,$charset,'UTF-8')."\";";
foreach ($all_file_of_directory as $key_value=>$value_info) {
SubLanguageManager::write_data_in_file ($dokeos_path_folder,$value_info,$key_value);
}

@ -1,4 +1,4 @@
<?php // $Id: languages.php 22382 2009-07-27 04:52:23Z iflorespaz $
<?php
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
@ -254,9 +254,9 @@ while ($row = Database::fetch_array($result_select)) {
if ($verified_if_is_sub_language===false) {
$verified_if_is_father=SubLanguageManager::check_if_language_is_father($row['id']);
$allow_use_sub_language = "&nbsp;<a href='new_sub_language.php?action=definenewsublanguage&id=".$row['id']."'>".Display::return_icon('mas.gif', get_lang('CreateSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
$allow_use_sub_language = "&nbsp;<a href='sub_language_add.php?action=definenewsublanguage&id=".$row['id']."'>".Display::return_icon('mas.gif', get_lang('CreateSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
if ($verified_if_is_father===true) {
//$allow_add_term_sub_language = "&nbsp;<a href='register_sub_language.php?action=registersublanguage&id=".$row['id']."'>".Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
//$allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=".$row['id']."'>".Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
$allow_add_term_sub_language='';
} else {
$allow_add_term_sub_language='';
@ -264,8 +264,8 @@ while ($row = Database::fetch_array($result_select)) {
} else {
$allow_use_sub_language='';
$all_information_of_sub_language=SubLanguageManager::get_all_information_of_language($row['id']);
$allow_add_term_sub_language = "&nbsp;<a href='register_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'=>'22','height'=>'22'))."</a>";
$allow_delete_sub_language = "&nbsp;<a href='new_sub_language.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_data.gif', get_lang('DeleteSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
$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'=>'22','height'=>'22'))."</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_data.gif', get_lang('DeleteSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
}
} else {

@ -1,297 +0,0 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/**
==================================================================================
@author Isaac flores paz <florespaz_isaac@hotmail.com> - Added 9 july of 2009
==================================================================================
*/
/*
==============================================================================
INIT SECTION
==============================================================================
*/
// name of the language file that needs to be included
$language_file = 'admin';
$cidReset = true;
require_once '../inc/global.inc.php';
require_once 'sub_language.class.php';
$this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] ='<script type="text/javascript">
$(document).ready(function() {
$("#sl_original_file").change(function () {
current_action=$("#Loadlanguage").attr("action");
current_action=current_action.split("original_file");
current_action=current_action[0];
current_action=current_action+"original_file="+$(this).attr("value")
$("#Loadlanguage").attr("action",current_action);
//
current_action=$("#Searchlanguage").attr("action");
current_action=current_action.split("original_file");
current_action=current_action[0];
current_action=current_action+"original_file="+$(this).attr("value")
$("#Searchlanguage").attr("action",current_action);
});
$(window).load(function () {
/*current_action=$("#Loadlanguage").attr("action");
current_action=current_action+"&original_file="+$("#sl_original_file").attr("value")
$("#Loadlanguage").attr("action",current_action);*/
});
$("#sl_original_file option[@value='.Security::remove_XSS($_REQUEST['original_file']).']").attr("selected","selected");
$(".save").click(function() {
button_name=$(this).attr("name");
button_name=button_name.split("_");
button_name=button_name[1];
is_id=$("#id_hidden_original_file").attr("value");
is_sublanguage_id=$("#id_hidden_sublanguage").attr("value");
is_variable_language="$"+button_name;
is_new_language=$("#txtid_"+button_name).attr("value");
if (is_new_language=="undefined") {
is_new_language="_";
}
is_file_language="'.Security::remove_XSS($_REQUEST['original_file']).'";
if (is_new_language.length>0 && is_new_language!="_") {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("#div_message_information_id").html("<div class=\"normal-message\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
},
type: "POST",
url: "../admin/add_by_ajax_sub_language.inc.php",
data: "new_language="+is_new_language+"&variable_language="+is_variable_language+"&file_language="+is_file_language+"&id="+is_id+"&sublanguage_id="+is_sublanguage_id,
success: function(datos) {
$("#div_message_information_id").html("<div class=\"confirmation-message\">'.get_lang('TheNewWordHasBeenAdded').'</div>");
} });
} else {
$("#div_message_information_id").html("<div class=\"error-message\">'.get_lang('FormHasErrorsPleaseComplete').'</div>");
}
});
});
</script>';
/*
==============================================================================
MAIN CODE
==============================================================================
*/
// setting the name of the tool
$tool_name = get_lang('CreateSubLanguage');
// setting breadcrumbs
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'languages.php', 'name' => get_lang('PlatformLanguages'));
require_once api_get_path(LIBRARY_PATH).'text.lib.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
$language_name=SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
$all_data_of_language=SubLanguageManager::get_all_information_of_language($_GET['id']);
$my_language=$language_name;
if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
$parent_id=intval($_GET['id']);
$language_id_exist=true;
} else {
$language_id_exist=false;
}
} else {
$language_name='';
$language_id_exist=false;
}
$language_name=get_lang('RegisterTermsOfSubLanguageForLanguage').' ( '.strtolower($language_name).' )';
// including the header file (which includes the banner itself)
$dokeos_path_folder=api_get_path('SYS_LANG_PATH').$all_data_of_language['dokeos_folder'];
//get file name example : forum.inc.php,gradebook.inc.php
if (!is_dir($dokeos_path_folder) || strlen($all_data_of_language['dokeos_folder'])==0) {
api_not_allowed(true);
}
Display :: display_header($language_name);
$all_file_of_directory=SubLanguageManager::get_all_data_of_dokeos_folder ($dokeos_path_folder);
$load_array_in_select=array();
sort($all_file_of_directory);
foreach ($all_file_of_directory as $value_all_file_of_directory) {
$load_array_in_select[$value_all_file_of_directory]=$value_all_file_of_directory;
}
$request_file='';
if (isset($_POST['original_file']) && $_POST['original_file']!='') {
$request_file=Security::remove_XSS($_POST['original_file']);
}
if (isset($_GET['original_file']) && $_GET['original_file']!='') {
$request_file=Security::remove_XSS($_GET['original_file']);
}
/*$form = new FormValidator('Loadlanguage', 'post', 'register_sub_language.php?id='.Security::remove_XSS($_GET['id']).'&original_file='.$request_file);
$class='plus';
$form->addElement('hidden','id_hidden_original_file',Security::remove_XSS($_REQUEST['id']),array('id'=>'id_hidden_original_file'));
$select_level = array ();
$radios_results_enabled[] = FormValidator :: createElement ('select', 'original_file', get_lang('File'),$load_array_in_select,array('id'=>'sl_original_file'));
$radios_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'SubmitLoadLanguage', get_lang('LoadLanguageFile'), 'class="'.$class.'"');
$radios_results_enabled[] = FormValidator :: createElement ('text', 'txt_search_word');
$radios_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'SubmitSearchLanguage', get_lang('Search'), 'class="search"');
$form->addGroup($radios_results_enabled);*/
echo '<div class="actions-message" >';
echo $language_name;
echo '</div>';
echo '<br/>';
/*echo '<div class="actions">';
$form->display();
echo '</div>';*/
$html.='<div style="float:left" class="actions" >';
$html.='<form style="float:left" id="Loadlanguage" name="Loadlanguage" method="post" action="register_sub_language.php?id='.Security::remove_XSS($_GET['id']).'&sub_language_id='.Security::remove_XSS($_GET['sub_language_id']).'&original_file='.$request_file.'" >';
$html.='<input type="hidden" name="id_hidden_original_file" id="id_hidden_original_file" value="'.Security::remove_XSS($_REQUEST['id']).'" />';
$html.='<input type="hidden" name="id_hidden_sublanguage" id="id_hidden_sublanguage" value="'.Security::remove_XSS($_REQUEST['sub_language_id']).'" />';
$html.='<select id="sl_original_file" name="original_file">';
//$html.='<option value="0">'.get_lang('SelectAChoice').'</option>';
foreach ($load_array_in_select as $index_radios_results_enabled=>$value_radios_results_enabled) {
$html.='<option value="'.$value_radios_results_enabled.'">'.$value_radios_results_enabled.'</option>';
}
$html.='</select>';
$html.='<button class="plus" name="SubmitLoadLanguage" type="submit">'.get_lang('LoadLanguageFile').'</button>';
$html.='</form>';
$html.='</div>';
$html.='<div style="float:left" class="actions">';
$html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="post" action="register_sub_language.php?id='.Security::remove_XSS($_GET['id']).'&sub_language_id='.Security::remove_XSS($_GET['sub_language_id']).'&original_file='.$request_file.'" >';
$html.='&nbsp;'.get_lang('OriginalName').'&nbsp; :&nbsp;';
$html.='<input name="txt_search_word" type="text" size="30" id="txt_search_word" value="" />';
$html.='<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
$html.='</form>';
$html.='</div>';
echo $html;
echo '<br/>';
echo '<br/>';
echo '<br/>';
//id
echo '<div id="div_message_information_id">&nbsp;</div>';
echo '<div class="actions-message"><strong>';
echo get_lang('AddTermsOfThisSubLanguage');
echo '</strong></div>';
echo '<br/>';
//allow see data in sortetable
if ($_REQUEST['original_file']) {
if (isset($_REQUEST['txt_search_word']) && strlen(trim($_REQUEST['txt_search_word']))==0) {
unset($list_info);
$search_data=false;
} else {
$search_data=true;
}
if($search_data===true) {
$parent_id=intval($_REQUEST['id']);
$sub_language_id=intval($_REQUEST['sub_language_id']);
$get_all_info_of_sub_language=SubLanguageManager::get_all_information_of_sub_language ($parent_id,$sub_language_id);
$dokeos_path_file=api_get_path('SYS_LANG_PATH').$all_data_of_language['dokeos_folder'].'/'.$request_file;
$dokeos_english_path_file=api_get_path('SYS_LANG_PATH').'english/'.$request_file;
$dokeos_sub_language_path_file=api_get_path('SYS_LANG_PATH').$get_all_info_of_sub_language['dokeos_folder'].'/'.$request_file;
if (file_exists($dokeos_sub_language_path_file)) {
$sub_language_exist=true;
} else {
$sub_language_exist=false;
}
$all_language_variable=SubLanguageManager::get_all_language_variable_in_file ($dokeos_path_file);
$all_english_language_variable=SubLanguageManager::get_all_language_variable_in_file($dokeos_english_path_file);
if ($sub_language_exist===true) {
$get_all_sub_language_variable=SubLanguageManager::get_all_language_variable_in_file($dokeos_sub_language_path_file);
}
$i=0;
foreach ($all_language_variable as $index_language_variable =>$value_language_variable) {
$use_field_name=substr($index_language_variable,1);
if ($sub_language_exist===true) {
foreach ($get_all_sub_language_variable as $index_get_all_sub_language_variable =>$value_get_all_sub_language_variable) {
if ($index_get_all_sub_language_variable==$index_language_variable) {
$value_sub_language=$value_get_all_sub_language_variable;
break;
} else {
$value_sub_language='';
}
}
}
$value_sub_language=strlen($value_sub_language)>0 ? $value_sub_language : '';
$obj_text='<textarea tabindex="1" rows="4" cols="40" name="txt_'.$use_field_name.'" id="txtid_'.$use_field_name.'" >'.substr($value_sub_language,1,(strlen($value_sub_language)-3)).'</textarea>';
$obj_button='<button class="save" type="button" name="btn_'.$use_field_name.'" id="btnid_'.$use_field_name.'" />'.get_lang('Save').'</button>';
$new_element_html=='<input type="hidden" name="code_language_id" id="code_language_id" value="'.Security::remove_XSS($_GET['id']).'" />';
if ($i==0) {
$obj_button=$obj_button.$new_element_html;
} else {
$obj_button=$obj_button;
}
foreach ($all_english_language_variable as $index_english_language_variable =>$value_english_language_variable) {
if ($index_english_language_variable==$index_language_variable) {
$add_english_language_in_array=$value_english_language_variable;
break;
}
}
//FIRST OPTION substr($index_language_variable,1,strlen($index_language_variable)),
$list_info[]=array($index_language_variable,substr($add_english_language_in_array,1,(strlen($add_english_language_in_array)-3)),substr($value_language_variable,1,(strlen($value_language_variable)-3)),$obj_text,$obj_button);
$i++;
}
}
if (isset($_REQUEST['txt_search_word']) && strlen(trim($_REQUEST['txt_search_word']))>0) {
foreach ($list_info as $index_list_info=>$value_list_info) {
$search='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
if (preg_match($search,$value_list_info[2])===0) {
unset($list_info[$index_list_info]);
}
}
}
}
$parameters=array('id'=>Security::remove_XSS($_GET['id']),'original_file'=>$request_file,'sub_language_id'=>Security::remove_XSS($_GET['sub_language_id']));
if (isset($_REQUEST['txt_search_word']) && strlen($_REQUEST['txt_search_word'])>0) {
$parameters['txt_search_word']=Security::remove_XSS($_REQUEST['txt_search_word']);
}
$table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
$table->set_additional_parameters($parameters);
//$table->set_header(0, '');
$table->set_header(0, get_lang('LanguageVariable'));
$table->set_header(1, get_lang('EnglishName'));
$table->set_header(2, get_lang('OriginalName'));
$table->set_header(3, get_lang('SubLanguage'),false);
$table->set_header(4, get_lang('Edit'),false);
/*$form_actions = array ();
$form_actions['addsublanguage'] = get_lang('AddSubLanguage');
$table->set_form_actions($form_actions);*/
$table->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
Display :: display_footer();
?>

@ -18,15 +18,22 @@ class SubLanguageManager {
/**
* Get all data of dokeos folder (forum.inc.php,gradebook.inc.php,notebook.inc.php)
* @param String The dokeos path folder (/var/www/my_dokeos/main/lang/spanish)
* @param bool true if we only want the "subname" trad4all instead of trad4all.inc.php
* @return Array All file of dokeos folder
*
*/
public static function get_all_data_of_dokeos_folder ($dokeos_path_folder) {
public static function get_all_data_of_dokeos_folder ($dokeos_path_folder,$only_main_name=false) {
$content_dir=array();
if (is_dir($dokeos_path_folder)) {
if ($dh = opendir($dokeos_path_folder)) {
while (($file = readdir($dh)) !== false) {
if ($file[0]<>'.' && substr($file,-4,strlen($file))=='.php') {
$content_dir[]=$file;
if ($file[0]<>'.' && substr($file,-4,strlen($file))=='.php') {
if ($only_main_name) {
if ($file!='' && strpos($file, '.inc.php'))
$content_dir[]=substr($file, 0, strpos($file, '.inc.php'));
} else {
$content_dir[]=$file;
}
}
}
@ -44,7 +51,7 @@ class SubLanguageManager {
*/
public static function get_all_information_of_sub_language ($parent_id,$sub_language_id) {
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql='SELECT * FROM '.$tbl_admin_languages.' WHERE parent_id="'.Database::escape_string($parent_id).'" AND id="'.Database::escape_string($sub_language_id).'"';
$sql='SELECT * FROM '.$tbl_admin_languages.' WHERE parent_id="'.Database::escape_string($parent_id).'" AND id="'.Database::escape_string($sub_language_id).'"';
$rs=Database::query($sql,__FILE__,__LINE__);
$all_information=array();
while ($row=Database::fetch_array($rs,'ASSOC')) {
@ -73,14 +80,14 @@ class SubLanguageManager {
* @return Array Contains all information of dokeos file
*/
public static function get_all_language_variable_in_file ($dokeos_path_file) {
$info_file=file($dokeos_path_file);
foreach ($info_file as $line) {
if (substr($line,0,1)!='$') { continue; }
list($var,$val) = split('=',$line,2);
$var = trim($var); $val = trim($val);
$res_list[$var] = $val;
}
return $res_list;
$info_file=file($dokeos_path_file);
foreach ($info_file as $line) {
if (substr($line,0,1)!='$') { continue; }
list($var,$val) = split('=',$line,2);
$var = trim($var); $val = trim($val);
$res_list[$var] = $val;
}
return $res_list;
}
/**

@ -0,0 +1,285 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/*
==============================================================================
INIT SECTION
==============================================================================
*/
// name of the language file that needs to be included
$language_file = 'admin';
$cidReset = true;
require_once '../inc/global.inc.php';
require_once 'sub_language.class.php';
require_once api_get_path(LIBRARY_PATH).'array.lib.php';
$this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] ='<script type="text/javascript">
$(document).ready(function() {
$(".save").click(function() {
button_name=$(this).attr("name");
button_array=button_name.split("|");
button_name=button_array[1];
file_id=button_array[2];
is_variable_language="$"+button_name;
is_new_language=$("#txtid_"+button_name).attr("value");
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",
beforeSend: function(objeto) {
$("#div_message_information_id").html("<div class=\"normal-message\"><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+"&id="+'.intval($_REQUEST['id']).'+"&sub="+'.intval($_REQUEST['sub_language_id']).',
success: function(datos) {
$("#div_message_information_id").html("<div class=\"confirmation-message\">'.get_lang('TheNewWordHasBeenAdded').'</div>");
} });
} else {
$("#div_message_information_id").html("<div class=\"error-message\">'.get_lang('FormHasErrorsPleaseComplete').'</div>");
}
});
});
</script>';
/*
==============================================================================
MAIN CODE
==============================================================================
*/
// setting the name of the tool
$tool_name = get_lang('CreateSubLanguage');
// setting breadcrumbs
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'languages.php', 'name' => get_lang('PlatformLanguages'));
require_once api_get_path(LIBRARY_PATH).'text.lib.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
$language_name=SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
$all_data_of_language=SubLanguageManager::get_all_information_of_language($_GET['id']);
$my_language=$language_name;
if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
$parent_id=intval($_GET['id']);
$language_id_exist=true;
} else {
$language_id_exist=false;
}
} else {
$language_name='';
$language_id_exist=false;
}
$language_name=get_lang('RegisterTermsOfSubLanguageForLanguage').' ( '.strtolower($language_name).' )';
$dokeos_path_folder=api_get_path('SYS_LANG_PATH').$all_data_of_language['dokeos_folder'];
//
if (!is_dir($dokeos_path_folder) || strlen($all_data_of_language['dokeos_folder'])==0) {
api_not_allowed(true);
}
Display :: display_header($language_name);
echo '<div class="actions-message" >';
echo $language_name;
echo '</div>';
echo '<br />';
$html.='<div style="float:left" class="actions">';
$html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="post" action="sub_language.php?id='.Security::remove_XSS($_GET['id']).'&sub_language_id='.Security::remove_XSS($_GET['sub_language_id']).'">';
$html.='&nbsp;'.get_lang('OriginalName').'&nbsp; :&nbsp;';
$html.='<input name="txt_search_word" type="text" size="50" id="txt_search_word" value="'.Security::remove_XSS($_REQUEST['txt_search_word']).'" />';
$html.="&nbsp;".'<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
$html.='</form>';
$html.='</div>';
echo $html;
echo '<br /><br /><br /><br />';
echo '<div id="div_message_information_id">&nbsp;</div>';
/**
* Search a term in the language
* @param string the term to search
* @param bool the search will include the variable definition of the term
* @param bool the search will include the english language variables
* @param bool the search will include the parent language variables of the sub language
* @param bool the search will include the sub language variables
* @author Julio Montoya
*
*/
function search_language_term($term, $search_in_variable = true , $search_in_english = true, $search_in_parent = true, $search_in_sub_language= true) {
//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
*/
//echo '<pre>';
// array with the list of files to load i.e trad4fall, notification, etc set in global.inc.php
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;
$list_info = array();
//echo '<pre>';
//print_r($language_files_to_load);
$term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
//@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
$sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
//config buttons
if (strlen($english_name_variable)>1500) {
$size =20;
} else {
$size =4;
}
$obj_text='<textarea rows="'.$size.'" cols="40" name="txt|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$parent_name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$parent_name_variable.'" />'.get_lang('Save').'</button>';
$list_info[]=array($lang_file.'.inc.php',
$parent_name_variable,
$english_name_variable,
$parent_variable_value,$obj_text,$obj_button);
}
}
}
//search in english
if ($search_in_english || $search_in_variable) {
$variables = $english_language_array[$lang_file];
foreach ($variables as $name_variable =>$variable_value) {
if (is_array($variable_value)) {
continue;
}
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;
}
}
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
$list_info[]=array($lang_file.'.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,$obj_text,$obj_button);
}
}
}
//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;
}
$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
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
$list_info[]=array($lang_file.'.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,$obj_text,$obj_button);
}
}
}
}
$list_info = array_unique_dimensional($list_info);
return $list_info;
}
//allow see data in sortetable
if (isset($_REQUEST['txt_search_word']) && strlen(trim($_REQUEST['txt_search_word']))!=0) {
$list_info = search_language_term($_REQUEST['txt_search_word'],true, true, true,true);
}
//var_dump($list_info);
$parameters=array('id'=>intval($_GET['id']),'sub_language_id'=>intval($_GET['sub_language_id']));
if (isset($_REQUEST['txt_search_word']) && strlen($_REQUEST['txt_search_word'])>0) {
$parameters['txt_search_word']=Security::remove_XSS($_REQUEST['txt_search_word']);
}
$table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
$table->set_additional_parameters($parameters);
//$table->set_header(0, '');
$table->set_header(0, get_lang('LanguageFile'));
$table->set_header(1, get_lang('LanguageVariable'));
$table->set_header(2, get_lang('EnglishName'));
$table->set_header(3, get_lang('OriginalName'));
$table->set_header(4, get_lang('SubLanguage'),false);
$table->set_header(5, get_lang('Edit'),false);
$table->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
Display :: display_footer();
?>

@ -1,10 +1,5 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
@author Isaac flores - Added 9 july of 2009
==============================================================================
*/
/*
==============================================================================
INIT SECTION
@ -260,7 +255,7 @@ if (isset($_POST['SubmitAddDeleteLanguage'])) {
//
if (isset($_GET['action']) && $_GET['action']=='definenewsublanguage') {
$text=$language_name;
$form = new FormValidator('addsublanguage', 'post', 'new_sub_language.php?id='.Security::remove_XSS($_GET['id']).'&action=definenewsublanguage');
$form = new FormValidator('addsublanguage', 'post', 'sub_language_add.php?id='.Security::remove_XSS($_GET['id']).'&action=definenewsublanguage');
$class='add';
$form->addElement('header', '', $text);
$form->addElement('text', 'original_name', get_lang('OriginalName'),'class="input_titles"');
@ -275,7 +270,7 @@ if (isset($_POST['SubmitAddDeleteLanguage'])) {
} else {
if (isset($_GET['action']) && $_GET['action']=='deletesublanguage') {
$text=$language_name;
$form = new FormValidator('deletesublanguage', 'post', 'new_sub_language.php?id='.Security::remove_XSS($_GET['id']).'&sub_language_id='.Security::remove_XSS($_GET['sub_language_id']));
$form = new FormValidator('deletesublanguage', 'post', 'sub_language_add.php?id='.Security::remove_XSS($_GET['id']).'&sub_language_id='.Security::remove_XSS($_GET['sub_language_id']));
$class='minus';
$form->addElement('header', '', $text);
$form->addElement('static', '', get_lang('OriginalName'),$original_name);

@ -0,0 +1,30 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
// including the global dokeos file
require_once '../inc/global.inc.php';
require_once 'sub_language.class.php';
/*
* search a term and return description from a glossary
*/
global $charset;
$new_language = Security::remove_XSS($_REQUEST['new_language']);
$language_variable = Security::remove_XSS($_REQUEST['variable_language']);
$file_id = Security::remove_XSS($_REQUEST['file_id']);
if (isset($new_language) && isset($language_variable) && isset($file_id)) {
$file_language = $language_files_to_load[$file_id].'.inc.php';
$id_language = intval($_REQUEST['id']);
$sub_language_id = intval($_REQUEST['sub']);
$all_data_of_language=SubLanguageManager::get_all_information_of_sub_language($id_language,$sub_language_id);
$dokeos_path_folder=api_get_path('SYS_LANG_PATH').$all_data_of_language['dokeos_folder'].'/'.$file_language;
$all_file_of_directory=SubLanguageManager::get_all_language_variable_in_file($dokeos_path_folder);
SubLanguageManager::add_file_in_language_directory ($dokeos_path_folder);
//update variable language
$all_file_of_directory[$language_variable]="\"".mb_convert_encoding($new_language,$charset,'UTF-8')."\";";
foreach ($all_file_of_directory as $key_value=>$value_info) {
SubLanguageManager::write_data_in_file ($dokeos_path_folder,$value_info,$key_value);
}
}

@ -518,16 +518,69 @@ else
// if we use the javascript version (without go button) we receive a get
// if we use the non-javascript version (with the go button) we receive a post
$user_language = '';
if(!empty($_GET['language']))
{
if(!empty($_GET['language'])) {
$user_language = $_GET["language"];
}
if (!empty($_POST["language_list"]))
{
if (!empty($_POST["language_list"])) {
$user_language = str_replace("index.php?language=","",$_POST["language_list"]);
}
/* This will only work if we are in the page to edit a sub_language */
if (api_get_self() == '/main/admin/sub_language.php' || api_get_self() == '/main/admin/sub_language_ajax.inc.php' ) {
require_once '../admin/sub_language.class.php';
// getting the arrays of files to load i.e notification, trad4all, etc
$language_files_to_load = SubLanguageManager::get_all_data_of_dokeos_folder(api_get_path(SYS_LANG_PATH).'english',true);
$parent_language = SubLanguageManager::get_all_information_of_language(intval($_REQUEST['id']));
$sub_language = SubLanguageManager::get_all_information_of_language(intval($_REQUEST['sub_language_id']));
$langpath = api_get_path(SYS_CODE_PATH).'lang/';
//echo '<pre>';
$english_language_array = $parent_language_array= $sub_language_array=array();
foreach ($language_files_to_load as $language_file_item) {
$lang_list_pre = array_keys($GLOBALS);
include $langpath.'english/'.$language_file_item.'.inc.php'; //loading english
$lang_list_post = array_keys($GLOBALS);
$lang_list_result = array_diff($lang_list_post, $lang_list_pre);
unset($lang_list_pre);
// ------ english language array
$english_language_array[$language_file_item]= compact($lang_list_result);
//cleaning the $GLOBALS
foreach($lang_list_result as $item) {
unset(${$item});
}
$parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
if (is_file($parent_file))
include $parent_file;
// ------ parent language array
$parent_language_array[$language_file_item]= compact($lang_list_result);
//cleaning the $GLOBALS
foreach($lang_list_result as $item) {
unset(${$item});
}
$sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
if (is_file($sub_file))
include $sub_file;
// ------ sub language array
$sub_language_array[$language_file_item]= compact($lang_list_result);
//cleaning the $GLOBALS
foreach($lang_list_result as $item) {
unset(${$item});
}
}
/*
print_r($english_language_array);
print_r($parent_language_array);
print_r($sub_language_array); exit
*/
}
// Checking if we have a valid language. If not we set it to the platform language.
$valid_languages=api_get_languages();
if (!in_array($user_language,$valid_languages['folder']))
@ -630,9 +683,9 @@ if (is_array($language_files)) {
}
}
}
}
// The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
// So, we have to reassign this variable again in order to keep its value right.
$charset = $charset_initial_value;

Loading…
Cancel
Save