sub_language.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script for sub-language administration
  5. * @package chamilo.admin.sub_language
  6. */
  7. /**
  8. * Init section
  9. */
  10. // name of the language file that needs to be included
  11. $language_file = 'admin';
  12. $cidReset = true;
  13. $this_script = 'sub_language';
  14. ////require_once '../inc/global.inc.php';
  15. require_once 'sub_language.class.php';
  16. $this_section = SECTION_PLATFORM_ADMIN;
  17. api_protect_admin_script();
  18. $htmlHeadXtra[] ='<script type="text/javascript">
  19. $(document).ready(function() {
  20. $(".save").click(function() {
  21. button_name=$(this).attr("name");
  22. button_array=button_name.split("|");
  23. button_name=button_array[1];
  24. file_id=button_array[2];
  25. is_variable_language="$"+button_name;
  26. is_new_language=$("#txtid_"+file_id+"_"+button_name).attr("value");
  27. if (is_new_language=="undefined") {
  28. is_new_language="_";
  29. }
  30. if (is_new_language.length>0 && is_new_language!="_" && file_id!="" && button_name!="") {
  31. $.ajax({
  32. contentType: "application/x-www-form-urlencoded",
  33. type: "POST",
  34. url: "../admin/sub_language_ajax.inc.php",
  35. 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']).',
  36. success: function(datos) {
  37. if (datos == "1") {
  38. $("#div_message_information_id").html("<div class=\"confirmation-message\">'.get_lang('TheNewWordHasBeenAdded').'</div>");
  39. } else {
  40. $("#div_message_information_id").html("<div class=\"warning-message\">" + datos +"</div>");
  41. }
  42. }
  43. });
  44. } else {
  45. $("#div_message_information_id").html("<div class=\"error-message\">'.get_lang('FormHasErrorsPleaseComplete').'</div>");
  46. }
  47. });
  48. });
  49. </script>';
  50. /**
  51. * Main code
  52. */
  53. // setting the name of the tool
  54. $tool_name = get_lang('CreateSubLanguage');
  55. // setting breadcrumbs
  56. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  57. $interbreadcrumb[] = array ('url' => 'languages.php', 'name' => get_lang('PlatformLanguages'));
  58. $sublanguage_folder_error = false;
  59. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  60. $language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
  61. $sub_language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['sub_language_id']);
  62. $all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
  63. $all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
  64. $sub_language_file = api_get_path(SYS_LANG_PATH).$all_data_of_sublanguage['dokeos_folder'];
  65. if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
  66. $sublanguage_folder_error = $sub_language_file.' '.get_lang('IsNotWritable');
  67. }
  68. if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
  69. $language_id_exist = true;
  70. } else {
  71. $language_id_exist = false;
  72. }
  73. } else {
  74. $language_name='';
  75. $language_id_exist=false;
  76. }
  77. $language_name = get_lang('RegisterTermsOfSubLanguageForLanguage').' ( '.strtolower($sub_language_name).' )';
  78. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'];
  79. if (!is_dir($path_folder) || strlen($all_data_of_language['dokeos_folder'])==0) {
  80. api_not_allowed(true);
  81. }
  82. Display :: display_header($language_name);
  83. echo '<div class="actions-message" >';
  84. echo $language_name;
  85. echo '</div>';
  86. if (!empty($_SESSION['msg'])) {
  87. echo $_SESSION['msg'];
  88. unset($_SESSION['msg']);
  89. } else {
  90. echo '<br />';
  91. }
  92. $txt_search_word = Security::remove_XSS($_REQUEST['txt_search_word']);
  93. $html.='<div style="float:left" class="actions">';
  94. $html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="GET" action="sub_language.php">';
  95. $html.='&nbsp;'.get_lang('OriginalName').'&nbsp; :&nbsp;';
  96. $html.='<input name="id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['id']).'" />';
  97. $html.='<input name="sub_language_id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['sub_language_id']).'" />';
  98. $html.='<input name="txt_search_word" type="text" size="50" id="txt_search_word" value="'.Security::remove_XSS($_REQUEST['txt_search_word']).'" />';
  99. $html.="&nbsp;".'<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
  100. $html.='</form>';
  101. $html.='</div>';
  102. echo $html;
  103. echo '<br /><br /><br />';
  104. if (!empty($sublanguage_folder_error)) {
  105. Display::display_warning_message($sublanguage_folder_error);
  106. }
  107. echo '<div id="div_message_information_id">&nbsp;</div>';
  108. /**
  109. * Search a term in the language
  110. * @param string the term to search
  111. * @param bool the search will include the variable definition of the term
  112. * @param bool the search will include the english language variables
  113. * @param bool the search will include the parent language variables of the sub language
  114. * @param bool the search will include the sub language variables
  115. * @author Julio Montoya
  116. *
  117. */
  118. function search_language_term($term, $search_in_variable = true , $search_in_english = true, $search_in_parent = true, $search_in_sub_language= true) {
  119. //These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION)
  120. /*
  121. 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
  122. $english_language_array
  123. $parent_language_array
  124. $sub_language_array
  125. $language_files_to_load
  126. */
  127. //echo '<pre>';
  128. // array with the list of files to load i.e trad4fall, notification, etc set in global.inc.php
  129. global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array;
  130. $language_files_to_load_keys = array_flip($language_files_to_load);
  131. $array_to_search = $parent_language_array;
  132. $list_info = array();
  133. //echo '<pre>';
  134. //print_r($language_files_to_load);
  135. $term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
  136. //@todo optimize this foreach
  137. foreach ($language_files_to_load as $lang_file) {
  138. //searching in parent language of the sub language
  139. if ($search_in_parent) {
  140. $variables = $parent_language_array[$lang_file];
  141. foreach ($variables as $parent_name_variable =>$parent_variable_value) {
  142. //arrays are avoided
  143. if (is_array($parent_variable_value)) {
  144. continue;
  145. }
  146. $founded = false;
  147. // searching the item in the parent tool
  148. if (preg_match($term,$parent_variable_value)!==0) {
  149. $founded = true;
  150. }
  151. if ($founded) {
  152. //loading variable from the english array
  153. $sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
  154. //loading variable from the english array
  155. $english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
  156. //config buttons
  157. /*if (strlen($english_name_variable)>1500) {
  158. $size =20;
  159. } else {
  160. $size =4;
  161. }*/
  162. $obj_text='<textarea 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.'" >'.$sub_language_name_variable.'</textarea>';
  163. $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>';
  164. $list_info[]=array($lang_file.'.inc.php',
  165. $parent_name_variable,
  166. $english_name_variable,
  167. $parent_variable_value,$obj_text,$obj_button);
  168. }
  169. }
  170. }
  171. //search in english
  172. if ($search_in_english || $search_in_variable) {
  173. $variables = $english_language_array[$lang_file];
  174. foreach ($variables as $name_variable =>$variable_value) {
  175. if (is_array($variable_value)) {
  176. continue;
  177. }
  178. if (is_array($variable_value))
  179. echo $lang_file;
  180. $founded = false;
  181. if ($search_in_english && $search_in_variable) {
  182. // searching the item in the parent tool
  183. if (preg_match($term,$variable_value)!==0 || preg_match($term,$name_variable)!==0 ) {
  184. $founded = true;
  185. }
  186. } else {
  187. if ($search_in_english) {
  188. if (preg_match($term,$variable_value)!==0) {
  189. $founded = true;
  190. }
  191. } else {
  192. if (preg_match($term,$name_variable)!==0) {
  193. $founded = true;
  194. }
  195. }
  196. }
  197. if ($founded) {
  198. //loading variable from the english array
  199. $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
  200. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  201. //config buttons
  202. $obj_text='<textarea 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.'" >'.$sub_language_name_variable.'</textarea>';
  203. $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>';
  204. //loading variable from the english array
  205. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  206. $list_info[]=array($lang_file.'.inc.php',
  207. $name_variable,
  208. $english_name_variable,
  209. $parent_variable_value,$obj_text,$obj_button);
  210. }
  211. }
  212. }
  213. //search in sub language
  214. if ($search_in_sub_language) {
  215. $variables = $sub_language_array[$lang_file];
  216. foreach ($variables as $name_variable =>$variable_value) {
  217. if (is_array($parent_variable_value)) {
  218. continue;
  219. }
  220. $founded = false;
  221. // searching the item in the parent tool
  222. if (preg_match($term,$variable_value)!==0) {
  223. $founded = true;
  224. }
  225. if ($founded) {
  226. //loading variable from the english array
  227. $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
  228. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  229. //config buttons
  230. $obj_text='<textarea 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.'" >'.$sub_language_name_variable.'</textarea>';
  231. $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>';
  232. //loading variable from the english array
  233. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  234. $list_info[]=array($lang_file.'.inc.php',
  235. $name_variable,
  236. $english_name_variable,
  237. $parent_variable_value,$obj_text,$obj_button);
  238. }
  239. }
  240. }
  241. }
  242. $list_info = ArrayClass::array_unique_dimensional($list_info);
  243. return $list_info;
  244. }
  245. /**
  246. * Output
  247. */
  248. //allow see data in sortetable
  249. if (isset($_REQUEST['txt_search_word'])) {
  250. //@todo fix to accept a char with 1 char
  251. if (strlen(trim($_REQUEST['txt_search_word']))>2) {
  252. $list_info = search_language_term($_REQUEST['txt_search_word'],true, true, true,true);
  253. }
  254. }
  255. $parameters=array('id'=>intval($_GET['id']),'sub_language_id'=>intval($_GET['sub_language_id']),'txt_search_word'=> $txt_search_word);
  256. $table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
  257. $table->set_additional_parameters($parameters);
  258. //$table->set_header(0, '');
  259. $table->set_header(0, get_lang('LanguageFile'));
  260. $table->set_header(1, get_lang('LanguageVariable'));
  261. $table->set_header(2, get_lang('EnglishName'));
  262. $table->set_header(3, get_lang('OriginalName'));
  263. $table->set_header(4, get_lang('SubLanguage'),false);
  264. $table->set_header(5, get_lang('Edit'),false);
  265. $table->display();
  266. /* FOOTER */
  267. Display :: display_footer();