languages.php 14 KB

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