languages.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 'sub_language.class.php';
  25. $this_section = SECTION_PLATFORM_ADMIN;
  26. api_protect_admin_script();
  27. //Ajax request
  28. if (isset($_POST['sent_http_request'])) {
  29. if (isset($_POST['visibility']) && $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 0) {
  30. if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
  31. if (SubLanguageManager::check_if_language_is_used($_POST['id']) == false) {
  32. SubLanguageManager::make_unavailable_language($_POST['id']);
  33. echo 'set_hidden';
  34. } else {
  35. echo 'confirm:' . intval($_POST['id']);
  36. }
  37. }
  38. }
  39. if (isset($_POST['visibility']) && $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 1) {
  40. if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
  41. SubLanguageManager::make_available_language($_POST['id']);
  42. echo 'set_visible';
  43. }
  44. }
  45. exit;
  46. }
  47. $htmlHeadXtra[] = '<script>
  48. $(document).ready(function() {
  49. //$(window).load(function () {
  50. $(".make_visible_and_invisible").attr("href","javascript:void(0)");
  51. //});
  52. $("td .make_visible_and_invisible").click(function () {
  53. make_visible="visible.png";
  54. make_invisible="invisible.png";
  55. id_link_tool=$(this).attr("id");
  56. id_img_link_tool="img"+id_link_tool;
  57. path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
  58. link_info_id=id_link_tool.split("linktool_");
  59. link_id=link_info_id[1];
  60. link_tool_info=path_name_of_imglinktool.split("/");
  61. my_image_tool=link_tool_info[link_tool_info.length-1];
  62. if (my_image_tool=="visible.png") {
  63. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
  64. my_visibility=0;
  65. } else {
  66. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
  67. my_visibility=1;
  68. }
  69. $.ajax({
  70. contentType: "application/x-www-form-urlencoded",
  71. beforeSend: function(objeto) {
  72. $("#id_content_message").html("<div class=\"normal-message\"><img src=\"' . api_get_path(WEB_PATH) . 'main/img/loading1.gif\" /></div>");
  73. },
  74. type: "POST",
  75. url: "../admin/languages.php",
  76. data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
  77. success: function(datos) {
  78. if (datos=="set_visible" || datos=="set_hidden") {
  79. $("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
  80. if (my_image_tool=="visible.png") {
  81. $("#"+id_img_link_tool).attr("alt","' . get_lang('MakeAvailable', '') . '");
  82. $("#"+id_img_link_tool).attr("title","' . get_lang('MakeAvailable', '') . '");
  83. } else {
  84. $("#"+id_img_link_tool).attr("alt","' . get_lang('MakeUnavailable', '') . '");
  85. $("#"+id_img_link_tool).attr("title","' . get_lang('MakeUnavailable', '') . '");
  86. }
  87. if (datos=="set_visible") {
  88. $("#id_content_message").html("<div class=\"confirmation-message\">' . get_lang('LanguageIsNowVisible', '') . '</div>");
  89. }
  90. if (datos=="set_hidden") {
  91. $("#id_content_message").html("<div class=\"confirmation-message\">' . get_lang('LanguageIsNowHidden', '') . '</div>");
  92. }
  93. }
  94. var action = datos.split(":")[0];
  95. if (action && action == "confirm") {
  96. var id = datos.split(":")[1];
  97. var sure = "<div class=\"warning-message\">'.get_lang('ThereAreUsersUsingThisLanguageYouWantToDisableThisLanguageAndSetUsersWithTheDefaultPortalLanguage').'</div><a href=\"languages.php?action=make_unavailable_confirmed&id="+id+"\" class=\"btn\">' . get_lang('MakeUnavailable') . '</a>";
  98. $("#id_content_message").html(sure);
  99. }
  100. } });
  101. });
  102. });
  103. </script>';
  104. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  105. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  106. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  107. /*
  108. ==============================================================================
  109. STORING THE CHANGES
  110. ==============================================================================
  111. */
  112. // we change the availability
  113. if (isset($_GET['action']) && $_GET['action'] == 'makeunavailable') {
  114. if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
  115. SubLanguageManager::make_unavailable_language($_GET['id']);
  116. }
  117. }
  118. if (isset($_GET['action']) && $_GET['action'] == 'makeavailable') {
  119. if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
  120. SubLanguageManager::make_available_language($_GET['id']);
  121. }
  122. }
  123. if (isset($_GET['action']) && $_GET['action'] == 'setplatformlanguage') {
  124. if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
  125. SubLanguageManager::set_platform_language($_GET['id']);
  126. }
  127. }
  128. if (isset($_POST['Submit']) && $_POST['Submit']) {
  129. // changing the name
  130. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  131. $result = Database::query($sql_update);
  132. // changing the Platform language
  133. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '') {
  134. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  135. //$result_2 = Database::query($sql_update_2);
  136. api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, api_get_current_access_url_id());
  137. }
  138. } elseif (isset($_POST['action'])) {
  139. switch ($_POST['action']) {
  140. case 'makeavailable' :
  141. if (count($_POST['id']) > 0) {
  142. $ids = array();
  143. foreach ($_POST['id'] as $index => $id) {
  144. $ids[] = Database::escape_string($id);
  145. }
  146. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('" . implode("','", $ids) . "')";
  147. Database::query($sql);
  148. }
  149. break;
  150. case 'makeunavailable' :
  151. if (count($_POST['id']) > 0) {
  152. $ids = array();
  153. foreach ($_POST['id'] as $index => $id) {
  154. $ids[] = Database::escape_string($id);
  155. }
  156. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('" . implode("','", $ids) . "')";
  157. Database::query($sql);
  158. }
  159. break;
  160. }
  161. }
  162. /*
  163. ==============================================================================
  164. MAIN CODE
  165. ==============================================================================
  166. */
  167. // setting the name of the tool
  168. $tool_name = get_lang('PlatformLanguages');
  169. // setting breadcrumbs
  170. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  171. // including the header file (which includes the banner itself)
  172. Display :: display_header($tool_name);
  173. if (isset($_GET['action']) && $_GET['action'] == 'make_unavailable_confirmed') {
  174. $language_info = SubLanguageManager::get_all_information_of_language($_GET['id']);
  175. if ($language_info['available'] == 1) {
  176. SubLanguageManager::make_unavailable_language($_GET['id']);
  177. $platform_language = api_get_setting('platformLanguage');
  178. UserManager::update_all_user_languages($language_info['english_name'], $platform_language);
  179. Display::display_confirmation_message(get_lang('LanguageIsNowHidden'));
  180. }
  181. }
  182. // displaying the explanation for this tool
  183. Display::display_normal_message(get_lang('PlatformLanguagesExplanation'));
  184. // selecting all the languages
  185. $sql_select = "SELECT * FROM $tbl_admin_languages";
  186. $result_select = Database::query($sql_select);
  187. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  188. $result_select_lang = Database::query($sql_select_lang);
  189. $row_lang = Database::fetch_array($result_select_lang);
  190. /*
  191. --------------------------------------
  192. DISPLAY THE TABLE
  193. --------------------------------------
  194. */
  195. // the table data
  196. $language_data = array();
  197. while ($row = Database::fetch_array($result_select)) {
  198. $row_td = array();
  199. $row_td[] = $row['id'];
  200. // the first column is the original name of the language OR a form containing the original name
  201. if (isset($_GET['action']) and $_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  202. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  203. $checked = ' checked="checked" ';
  204. }
  205. $row_td[] = '<input type="hidden" name="edit_id" value="' . Security::remove_XSS($_GET['id']) . '" /><input type="text" name="txt_name" value="' . $row['original_name'] . '" /> '
  206. . '<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" />';
  207. } else {
  208. $row_td[] = $row['original_name'];
  209. }
  210. // the second column
  211. $row_td[] = $row['english_name'];
  212. // the third column
  213. $row_td[] = $row['dokeos_folder'];
  214. if ($row['english_name'] == $row_lang['selected_value']) {
  215. $setplatformlanguage = Display::return_icon('languages.png', get_lang('CurrentLanguagesPortal'), '', ICON_SIZE_SMALL);
  216. } else {
  217. $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'), '', ICON_SIZE_SMALL) . "</a>";
  218. }
  219. $allow_use_sub_language = '';
  220. $allow_add_term_sub_language = '';
  221. $allow_delete_sub_language = '';
  222. if (api_get_setting('allow_use_sub_language') == 'true') {
  223. $verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
  224. if ($verified_if_is_sub_language === false) {
  225. $verified_if_is_father = SubLanguageManager::check_if_language_is_father($row['id']);
  226. $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(), ICON_SIZE_SMALL) . "</a>";
  227. if ($verified_if_is_father === true) {
  228. //$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'=>ICON_SIZE_SMALL,'height'=>ICON_SIZE_SMALL))."</a>";
  229. $allow_add_term_sub_language = '';
  230. } else {
  231. $allow_add_term_sub_language = '';
  232. }
  233. } else {
  234. $allow_use_sub_language = '';
  235. $all_information_of_sub_language = SubLanguageManager::get_all_information_of_language($row['id']);
  236. $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' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
  237. $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' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
  238. }
  239. }
  240. if ($row['english_name'] == $row_lang['selected_value']) {
  241. $row_td[] = Display::return_icon('visible.png', get_lang('Visible'))."<a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>
  242. &nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
  243. } else {
  244. if ($row['available'] == 1) {
  245. $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']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
  246. } else {
  247. $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']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
  248. }
  249. }
  250. $language_data[] = $row_td;
  251. }
  252. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  253. $table->set_header(0, '');
  254. $table->set_header(1, get_lang('OriginalName'));
  255. $table->set_header(2, get_lang('EnglishName'));
  256. $table->set_header(3, get_lang('DokeosFolder'));
  257. $table->set_header(4, get_lang('Properties'));
  258. $form_actions = array();
  259. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  260. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  261. $table->set_form_actions($form_actions);
  262. echo '<div id="id_content_message">&nbsp;</div>';
  263. $table->display();
  264. /*
  265. ==============================================================================
  266. FOOTER
  267. ==============================================================================
  268. */
  269. Display :: display_footer();
  270. ?>