sub_language.php 12 KB

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