sub_language.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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).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=\"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. $intro = sprintf(get_lang('RegisterTermsOfSubLanguageForX'), 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 $intro;
  82. echo '<br />';
  83. printf(get_lang('ParentLanguageX'), $language_name);
  84. echo '</div>';
  85. if (!empty($_SESSION['msg'])) {
  86. echo $_SESSION['msg'];
  87. unset($_SESSION['msg']);
  88. } else {
  89. echo '<br />';
  90. }
  91. $txt_search_word = Security::remove_XSS($_REQUEST['txt_search_word']);
  92. $html ='<div style="float:left" class="actions">';
  93. $html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="GET" action="sub_language.php">';
  94. $html.='&nbsp;'.get_lang('OriginalName').'&nbsp; :&nbsp;';
  95. $html.='<input name="id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['id']).'" />';
  96. $html.='<input name="sub_language_id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['sub_language_id']).'" />';
  97. $html.='<input name="txt_search_word" type="text" size="50" id="txt_search_word" value="'.Security::remove_XSS($_REQUEST['txt_search_word']).'" />';
  98. $html.="&nbsp;".'<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
  99. $html.='</form>';
  100. $html.='</div>';
  101. echo $html;
  102. echo '<br /><br /><br />';
  103. if (!empty($sublanguage_folder_error)) {
  104. Display::display_warning_message($sublanguage_folder_error);
  105. }
  106. echo '<div id="div_message_information_id">&nbsp;</div>';
  107. /**
  108. * Search a term in the language
  109. * @param string $term the term to search
  110. * @param bool $search_in_variable the search will include the variable definition of the term
  111. * @param bool $search_in_english the search will include the english language variables
  112. * @param bool $search_in_parent the search will include the parent language variables of the sub language
  113. * @param bool $search_in_sub_language the search will include the sub language variables
  114. * @author Julio Montoya
  115. *
  116. */
  117. function search_language_term(
  118. $term,
  119. $search_in_variable = true,
  120. $search_in_english = true,
  121. $search_in_parent = true,
  122. $search_in_sub_language = true
  123. ) {
  124. //These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION)
  125. /*
  126. 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
  127. $english_language_array
  128. $parent_language_array
  129. $sub_language_array
  130. $language_files_to_load
  131. */
  132. global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array;
  133. $language_files_to_load_keys = array_flip($language_files_to_load);
  134. $array_to_search = $parent_language_array;
  135. $list_info = array();
  136. $term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
  137. //@todo optimize this foreach
  138. foreach ($language_files_to_load as $lang_file) {
  139. //searching in parent language of the sub language
  140. if ($search_in_parent) {
  141. $variables = $parent_language_array[$lang_file];
  142. foreach ($variables as $parent_name_variable =>$parent_variable_value) {
  143. //arrays are avoided
  144. if (is_array($parent_variable_value)) {
  145. continue;
  146. }
  147. $founded = false;
  148. // searching the item in the parent tool
  149. if (preg_match($term,$parent_variable_value)!==0) {
  150. $founded = true;
  151. }
  152. if ($founded) {
  153. //loading variable from the english array
  154. $sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
  155. //loading variable from the english array
  156. $english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
  157. //config buttons
  158. /*if (strlen($english_name_variable)>1500) {
  159. $size =20;
  160. } else {
  161. $size =4;
  162. }*/
  163. $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>';
  164. $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>';
  165. $list_info[] = array(
  166. $lang_file . '.inc.php',
  167. $parent_name_variable,
  168. $english_name_variable,
  169. $parent_variable_value,
  170. $obj_text,
  171. $obj_button
  172. );
  173. }
  174. }
  175. }
  176. //search in english
  177. if ($search_in_english || $search_in_variable) {
  178. $variables = $english_language_array[$lang_file];
  179. foreach ($variables as $name_variable =>$variable_value) {
  180. if (is_array($variable_value)) {
  181. continue;
  182. }
  183. if (is_array($variable_value))
  184. echo $lang_file;
  185. $founded = false;
  186. if ($search_in_english && $search_in_variable) {
  187. // searching the item in the parent tool
  188. if (preg_match($term,$variable_value)!==0 || preg_match($term,$name_variable)!==0 ) {
  189. $founded = true;
  190. }
  191. } else {
  192. if ($search_in_english) {
  193. if (preg_match($term,$variable_value)!==0) {
  194. $founded = true;
  195. }
  196. } else {
  197. if (preg_match($term,$name_variable)!==0) {
  198. $founded = true;
  199. }
  200. }
  201. }
  202. if ($founded) {
  203. //loading variable from the english array
  204. $sub_language_name_variable = null;
  205. if (isset($sub_language_array[$lang_file][$name_variable])) {
  206. $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
  207. }
  208. $parent_variable_value = null;
  209. if (isset($parent_language_array[$lang_file][$name_variable])) {
  210. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  211. }
  212. //config buttons
  213. $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.'" >'.
  214. $sub_language_name_variable.'
  215. </textarea>';
  216. $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>';
  217. //loading variable from the english array
  218. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  219. $list_info[] = array(
  220. $lang_file . '.inc.php',
  221. $name_variable,
  222. $english_name_variable,
  223. $parent_variable_value,
  224. $obj_text,
  225. $obj_button
  226. );
  227. }
  228. }
  229. }
  230. // Search in sub language
  231. if ($search_in_sub_language) {
  232. $variables = $sub_language_array[$lang_file];
  233. foreach ($variables as $name_variable =>$variable_value) {
  234. if (is_array($parent_variable_value)) {
  235. continue;
  236. }
  237. $founded = false;
  238. // searching the item in the parent tool
  239. if (preg_match($term,$variable_value)!==0) {
  240. $founded = true;
  241. }
  242. if ($founded) {
  243. //loading variable from the english array
  244. $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
  245. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  246. //config buttons
  247. $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>';
  248. $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>';
  249. //loading variable from the english array
  250. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  251. $list_info[]=array($lang_file.'.inc.php',
  252. $name_variable,
  253. $english_name_variable,
  254. $parent_variable_value,$obj_text,$obj_button);
  255. }
  256. }
  257. }
  258. }
  259. $list_info = array_unique_dimensional($list_info);
  260. return $list_info;
  261. }
  262. // Allow see data in sort table
  263. $list_info = array();
  264. if (isset($_REQUEST['txt_search_word'])) {
  265. //@todo fix to accept a char with 1 char
  266. if (strlen(trim($_REQUEST['txt_search_word']))>2) {
  267. $list_info = search_language_term(
  268. $_REQUEST['txt_search_word'],
  269. true,
  270. true,
  271. true,
  272. true
  273. );
  274. }
  275. }
  276. $parameters = array(
  277. 'id' => intval($_GET['id']),
  278. 'sub_language_id' => intval($_GET['sub_language_id']),
  279. 'txt_search_word' => $txt_search_word
  280. );
  281. $table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
  282. $table->set_additional_parameters($parameters);
  283. $table->set_header(0, get_lang('LanguageFile'));
  284. $table->set_header(1, get_lang('LanguageVariable'));
  285. $table->set_header(2, get_lang('EnglishName'));
  286. $table->set_header(3, get_lang('OriginalName'));
  287. $table->set_header(4, get_lang('SubLanguage'),false);
  288. $table->set_header(5, get_lang('Edit'),false);
  289. $table->display();
  290. Display :: display_footer();