sub_language.php 12 KB

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