sub_language.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. beforeSend: function(objeto) {
  34. $("#div_message_information_id").html("<div class=\"normal-message\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
  35. },
  36. type: "POST",
  37. url: "../admin/sub_language_ajax.inc.php",
  38. 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']).',
  39. success: function(datos) {
  40. if (datos == "1") {
  41. $("#div_message_information_id").html("<div class=\"confirmation-message\">'.get_lang('TheNewWordHasBeenAdded').'</div>");
  42. } else {
  43. $("#div_message_information_id").html("<div class=\"warning-message\">" + datos +"</div>");
  44. }
  45. }
  46. });
  47. } else {
  48. $("#div_message_information_id").html("<div class=\"error-message\">'.get_lang('FormHasErrorsPleaseComplete').'</div>");
  49. }
  50. });
  51. });
  52. </script>';
  53. /**
  54. * Main code
  55. */
  56. // setting the name of the tool
  57. $tool_name = get_lang('CreateSubLanguage');
  58. // setting breadcrumbs
  59. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  60. $interbreadcrumb[] = array ('url' => 'languages.php', 'name' => get_lang('PlatformLanguages'));
  61. $sublanguage_folder_error = false;
  62. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  63. $language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
  64. $sub_language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['sub_language_id']);
  65. $all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
  66. $all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
  67. $sub_language_file = api_get_path(SYS_LANG_PATH).$all_data_of_sublanguage['dokeos_folder'];
  68. if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
  69. $sublanguage_folder_error = $sub_language_file.' '.get_lang('IsNotWritable');
  70. }
  71. if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
  72. $language_id_exist = true;
  73. } else {
  74. $language_id_exist = false;
  75. }
  76. } else {
  77. $language_name='';
  78. $language_id_exist=false;
  79. }
  80. $language_name = get_lang('RegisterTermsOfSubLanguageForLanguage').' ( '.strtolower($sub_language_name).' )';
  81. $path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'];
  82. if (!is_dir($path_folder) || strlen($all_data_of_language['dokeos_folder'])==0) {
  83. api_not_allowed(true);
  84. }
  85. Display :: display_header($language_name);
  86. echo '<div class="actions-message" >';
  87. echo $language_name;
  88. echo '</div>';
  89. if (!empty($_SESSION['msg'])) {
  90. echo $_SESSION['msg'];
  91. unset($_SESSION['msg']);
  92. } else {
  93. echo '<br />';
  94. }
  95. $txt_search_word = Security::remove_XSS($_REQUEST['txt_search_word']);
  96. $html.='<div style="float:left" class="actions">';
  97. $html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="GET" action="sub_language.php">';
  98. $html.='&nbsp;'.get_lang('OriginalName').'&nbsp; :&nbsp;';
  99. $html.='<input name="id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['id']).'" />';
  100. $html.='<input name="sub_language_id" type="hidden" id="id" value="'.Security::remove_XSS($_REQUEST['sub_language_id']).'" />';
  101. $html.='<input name="txt_search_word" type="text" size="50" id="txt_search_word" value="'.Security::remove_XSS($_REQUEST['txt_search_word']).'" />';
  102. $html.="&nbsp;".'<button name="SubmitSearchLanguage" class="search" type="submit">'.get_lang('Search').'</button>';
  103. $html.='</form>';
  104. $html.='</div>';
  105. echo $html;
  106. echo '<br /><br /><br />';
  107. if (!empty($sublanguage_folder_error)) {
  108. Display::display_warning_message($sublanguage_folder_error);
  109. }
  110. echo '<div id="div_message_information_id">&nbsp;</div>';
  111. /**
  112. * Search a term in the language
  113. * @param string the term to search
  114. * @param bool the search will include the variable definition of the term
  115. * @param bool the search will include the english language variables
  116. * @param bool the search will include the parent language variables of the sub language
  117. * @param bool the search will include the sub language variables
  118. * @author Julio Montoya
  119. *
  120. */
  121. function search_language_term($term, $search_in_variable = true , $search_in_english = true, $search_in_parent = true, $search_in_sub_language= true) {
  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. //echo '<pre>';
  131. // array with the list of files to load i.e trad4fall, notification, etc set in global.inc.php
  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. //echo '<pre>';
  137. //print_r($language_files_to_load);
  138. $term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
  139. //@todo optimize this foreach
  140. foreach ($language_files_to_load as $lang_file) {
  141. //searching in parent language of the sub language
  142. if ($search_in_parent) {
  143. $variables = $parent_language_array[$lang_file];
  144. foreach ($variables as $parent_name_variable =>$parent_variable_value) {
  145. //arrays are avoided
  146. if (is_array($parent_variable_value)) {
  147. continue;
  148. }
  149. $founded = false;
  150. // searching the item in the parent tool
  151. if (preg_match($term,$parent_variable_value)!==0) {
  152. $founded = true;
  153. }
  154. if ($founded) {
  155. //loading variable from the english array
  156. $sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
  157. //loading variable from the english array
  158. $english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
  159. //config buttons
  160. /*if (strlen($english_name_variable)>1500) {
  161. $size =20;
  162. } else {
  163. $size =4;
  164. }*/
  165. $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>';
  166. $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>';
  167. $list_info[]=array($lang_file.'.inc.php',
  168. $parent_name_variable,
  169. $english_name_variable,
  170. $parent_variable_value,$obj_text,$obj_button);
  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 = $sub_language_array[$lang_file][$name_variable];
  203. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  204. //config buttons
  205. $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>';
  206. $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>';
  207. //loading variable from the english array
  208. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  209. $list_info[]=array($lang_file.'.inc.php',
  210. $name_variable,
  211. $english_name_variable,
  212. $parent_variable_value,$obj_text,$obj_button);
  213. }
  214. }
  215. }
  216. //search in sub language
  217. if ($search_in_sub_language) {
  218. $variables = $sub_language_array[$lang_file];
  219. foreach ($variables as $name_variable =>$variable_value) {
  220. if (is_array($parent_variable_value)) {
  221. continue;
  222. }
  223. $founded = false;
  224. // searching the item in the parent tool
  225. if (preg_match($term,$variable_value)!==0) {
  226. $founded = true;
  227. }
  228. if ($founded) {
  229. //loading variable from the english array
  230. $sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
  231. $parent_variable_value = $parent_language_array[$lang_file][$name_variable];
  232. //config buttons
  233. $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>';
  234. $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>';
  235. //loading variable from the english array
  236. $english_name_variable = $english_language_array[$lang_file][$name_variable];
  237. $list_info[]=array($lang_file.'.inc.php',
  238. $name_variable,
  239. $english_name_variable,
  240. $parent_variable_value,$obj_text,$obj_button);
  241. }
  242. }
  243. }
  244. }
  245. $list_info = ArrayClass::array_unique_dimensional($list_info);
  246. return $list_info;
  247. }
  248. /**
  249. * Output
  250. */
  251. //allow see data in sortetable
  252. if (isset($_REQUEST['txt_search_word'])) {
  253. //@todo fix to accept a char with 1 char
  254. if (strlen(trim($_REQUEST['txt_search_word']))>2) {
  255. $list_info = search_language_term($_REQUEST['txt_search_word'],true, true, true,true);
  256. }
  257. }
  258. $parameters=array('id'=>intval($_GET['id']),'sub_language_id'=>intval($_GET['sub_language_id']),'txt_search_word'=> $txt_search_word);
  259. $table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
  260. $table->set_additional_parameters($parameters);
  261. //$table->set_header(0, '');
  262. $table->set_header(0, get_lang('LanguageFile'));
  263. $table->set_header(1, get_lang('LanguageVariable'));
  264. $table->set_header(2, get_lang('EnglishName'));
  265. $table->set_header(3, get_lang('OriginalName'));
  266. $table->set_header(4, get_lang('SubLanguage'),false);
  267. $table->set_header(5, get_lang('Edit'),false);
  268. $table->display();
  269. /* FOOTER */
  270. Display :: display_footer();