languages.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This page allows the platform admin to decide which languages should
  5. * be available in the language selection menu in the login page. This can be
  6. * useful for countries with more than one official language (like Belgium:
  7. * Dutch, French and German) or international organisations that are active in
  8. * a limited number of countries.
  9. *
  10. * @author Patrick Cool, main author
  11. * @author Roan EMbrechts, code cleaning
  12. * @since Dokeos 1.6
  13. * @package chamilo.admin
  14. */
  15. /**
  16. * INIT SECTION
  17. */
  18. // name of the language file that needs to be included
  19. $language_file = 'admin';
  20. // we are in the admin area so we do not need a course id
  21. $cidReset = true;
  22. // include global script
  23. require_once '../inc/global.inc.php';
  24. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  25. require_once 'sub_language.class.php';
  26. $this_section = SECTION_PLATFORM_ADMIN;
  27. api_protect_admin_script();
  28. //Ajax request
  29. if (isset($_POST['sent_http_request'])) {
  30. if (isset($_POST['visibility']) && $_POST['visibility']==strval(intval($_POST['visibility'])) && $_POST['visibility']==0) {
  31. if (isset($_POST['id'])&& $_POST['id']==strval(intval($_POST['id']))) {
  32. SubLanguageManager::make_unavailable_language($_POST['id']);
  33. echo 'set_hidden';
  34. }
  35. }
  36. if (isset($_POST['visibility']) && $_POST['visibility']==strval(intval($_POST['visibility'])) && $_POST['visibility']==1) {
  37. if (isset($_POST['id'])&& $_POST['id']==strval(intval($_POST['id']))) {
  38. SubLanguageManager::make_available_language($_POST['id']);
  39. echo 'set_visible';
  40. }
  41. }
  42. exit;
  43. }
  44. $htmlHeadXtra[] ='<script type="text/javascript">
  45. $(document).ready(function() {
  46. //$(window).load(function () {
  47. $(".make_visible_and_invisible").attr("href","javascript:void(0)");
  48. //});
  49. $("td .make_visible_and_invisible").click(function () {
  50. make_visible="visible.png";
  51. make_invisible="invisible.png";
  52. id_link_tool=$(this).attr("id");
  53. id_img_link_tool="img"+id_link_tool;
  54. path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
  55. link_info_id=id_link_tool.split("linktool_");
  56. link_id=link_info_id[1];
  57. link_tool_info=path_name_of_imglinktool.split("/");
  58. my_image_tool=link_tool_info[link_tool_info.length-1];
  59. if (my_image_tool=="visible.png") {
  60. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
  61. my_visibility=0;
  62. } else {
  63. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
  64. my_visibility=1;
  65. }
  66. $.ajax({
  67. contentType: "application/x-www-form-urlencoded",
  68. beforeSend: function(objeto) {
  69. $("#id_content_message").html("<div class=\"normal-message\"><img src=\'/main/inc/lib/javascript/indicator.gif\' /></div>");
  70. },
  71. type: "POST",
  72. url: "../admin/languages.php",
  73. data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
  74. success: function(datos) {
  75. $("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
  76. if (my_image_tool=="visible.png") {
  77. $("#"+id_img_link_tool).attr("alt","'.get_lang('MakeAvailable', '').'");
  78. $("#"+id_img_link_tool).attr("title","'.get_lang('MakeAvailable', '').'");
  79. } else {
  80. $("#"+id_img_link_tool).attr("alt","'.get_lang('MakeUnavailable', '').'");
  81. $("#"+id_img_link_tool).attr("title","'.get_lang('MakeUnavailable', '').'");
  82. }
  83. if (datos=="set_visible") {
  84. $("#id_content_message").html("<div class=\"confirmation-message\">'.get_lang('LanguageIsNowVisible', '').'</div>");
  85. } else {
  86. $("#id_content_message").html("<div class=\"confirmation-message\">'.get_lang('LanguageIsNowHidden', '').'</div>");
  87. }
  88. } });
  89. });
  90. });
  91. </script>';
  92. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  93. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  94. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  95. /*
  96. ==============================================================================
  97. STORING THE CHANGES
  98. ==============================================================================
  99. */
  100. // we change the availability
  101. if ($_GET['action'] == 'makeunavailable') {
  102. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  103. SubLanguageManager::make_unavailable_language($_GET['id']);
  104. }
  105. }
  106. if ($_GET['action'] == 'makeavailable') {
  107. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  108. SubLanguageManager::make_available_language($_GET['id']);
  109. }
  110. }
  111. if ($_GET['action'] == 'setplatformlanguage') {
  112. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  113. SubLanguageManager::set_platform_language($_GET['id']);
  114. }
  115. }
  116. if ($_POST['Submit'])
  117. {
  118. // changing the name
  119. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  120. $result = Database::query($sql_update);
  121. // changing the Platform language
  122. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
  123. {
  124. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  125. //$result_2 = Database::query($sql_update_2);
  126. api_set_setting('platformLanguage',$_POST['platformlanguage'],null,null,$_configuration['access_url']);
  127. }
  128. }
  129. elseif (isset($_POST['action']))
  130. {
  131. switch ($_POST['action'])
  132. {
  133. case 'makeavailable' :
  134. if (count($_POST['id']) > 0)
  135. {
  136. $ids = array ();
  137. foreach ($_POST['id'] as $index => $id)
  138. {
  139. $ids[] = Database::escape_string($id);
  140. }
  141. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
  142. Database::query($sql);
  143. }
  144. break;
  145. case 'makeunavailable' :
  146. if (count($_POST['id']) > 0)
  147. {
  148. $ids = array ();
  149. foreach ($_POST['id'] as $index => $id)
  150. {
  151. $ids[] = Database::escape_string($id);
  152. }
  153. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  154. Database::query($sql);
  155. }
  156. break;
  157. }
  158. }
  159. /*
  160. ==============================================================================
  161. MAIN CODE
  162. ==============================================================================
  163. */
  164. // setting the name of the tool
  165. $tool_name = get_lang('PlatformLanguages');
  166. // setting breadcrumbs
  167. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  168. // including the header file (which includes the banner itself)
  169. Display :: display_header($tool_name);
  170. // displaying the naam of the tool
  171. //api_display_tool_title($tool_name);
  172. // displaying the explanation for this tool
  173. echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
  174. // selecting all the languages
  175. $sql_select = "SELECT * FROM $tbl_admin_languages";
  176. $result_select = Database::query($sql_select);
  177. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  178. $result_select_lang = Database::query($sql_select_lang);
  179. $row_lang=Database::fetch_array($result_select_lang);
  180. /*
  181. --------------------------------------
  182. DISPLAY THE TABLE
  183. --------------------------------------
  184. */
  185. // the table data
  186. $language_data = array ();
  187. while ($row = Database::fetch_array($result_select)) {
  188. $row_td = array ();
  189. $row_td[] = $row['id'];
  190. // the first column is the original name of the language OR a form containing the original name
  191. if ($_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  192. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  193. $checked = ' checked="checked" ';
  194. }
  195. $row_td[] = '<input type="hidden" name="edit_id" value="'.Security::remove_XSS($_GET['id']).'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
  196. . '<input type="checkbox" '.$checked.'name="platformlanguage" id="platformlanguage" value="'.$row['english_name'].'" /><label for="platformlanguage">'.$row['original_name'].' '.get_lang('AsPlatformLanguage').'</label> <input type="submit" name="Submit" value="'.get_lang('Ok').'" /><a name="value" />';
  197. } else {
  198. $row_td[] = $row['original_name'];
  199. }
  200. // the second column
  201. $row_td[] = $row['english_name'];
  202. // the third column
  203. $row_td[] = $row['dokeos_folder'];
  204. if ($row['english_name'] == $row_lang['selected_value']){
  205. $setplatformlanguage = Display::return_icon('languages.png', get_lang('CurrentLanguagesPortal'),'',22);
  206. } else {
  207. $setplatformlanguage = "<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureYouWantToSetThisLanguageAsThePortalDefault'))."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">".Display::return_icon('languages_na.png',get_lang('SetLanguageAsDefault'),'',22)."</a>";
  208. }
  209. if (api_get_setting('allow_use_sub_language')=='true') {
  210. $verified_if_is_sub_language=SubLanguageManager::check_if_language_is_sub_language($row['id']);
  211. if ($verified_if_is_sub_language===false) {
  212. $verified_if_is_father=SubLanguageManager::check_if_language_is_father($row['id']);
  213. $allow_use_sub_language = "&nbsp;<a href='sub_language_add.php?action=definenewsublanguage&id=".$row['id']."'>".Display::return_icon('new_language.png', get_lang('CreateSubLanguage'),array(),22)."</a>";
  214. if ($verified_if_is_father===true) {
  215. //$allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=".$row['id']."'>".Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
  216. $allow_add_term_sub_language='';
  217. } else {
  218. $allow_add_term_sub_language='';
  219. }
  220. } else {
  221. $allow_use_sub_language='';
  222. $all_information_of_sub_language=SubLanguageManager::get_all_information_of_language($row['id']);
  223. $allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=".Security::remove_XSS($all_information_of_sub_language['parent_id'])."&sub_language_id=".Security::remove_XSS($row['id'])."'>".Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
  224. $allow_delete_sub_language = "&nbsp;<a href='sub_language_add.php?action=deletesublanguage&id=".Security::remove_XSS($all_information_of_sub_language['parent_id'])."&sub_language_id=".Security::remove_XSS($row['id'])."'>".Display::return_icon('delete.png', get_lang('DeleteSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
  225. }
  226. } else {
  227. $allow_use_sub_language='';
  228. $allow_add_term_sub_language='';
  229. }
  230. if ($row['available'] == 1) {
  231. $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeunavailable&id=".$row['id']."'>".Display::return_icon('visible.png', get_lang('MakeUnavailable'),array('id'=>'imglinktool_'.$row['id']),22)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  232. //$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('visible.gif', get_lang('MakeUnavailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
  233. } else {
  234. $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeavailable&id=".$row['id']."'>".Display::return_icon('invisible.png', get_lang('MakeAvailable'),array('id'=>'imglinktool_'.$row['id']),22)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  235. //$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('invisible.gif', get_lang('MakeAvailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
  236. }
  237. $language_data[] = $row_td;
  238. }
  239. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  240. $table->set_header(0, '');
  241. $table->set_header(1, get_lang('OriginalName'));
  242. $table->set_header(2, get_lang('EnglishName'));
  243. $table->set_header(3, get_lang('DokeosFolder'));
  244. $table->set_header(4, get_lang('Properties'));
  245. $form_actions = array ();
  246. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  247. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  248. $table->set_form_actions($form_actions);
  249. echo '<div id="id_content_message">&nbsp;</div>';
  250. $table->display();
  251. /*
  252. ==============================================================================
  253. FOOTER
  254. ==============================================================================
  255. */
  256. Display :: display_footer();
  257. ?>