languages.php 17 KB

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