languages.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. *
  13. * @since Dokeos 1.6
  14. */
  15. // we are in the admin area so we do not need a course id
  16. $cidReset = true;
  17. // include global script
  18. require_once __DIR__.'/../inc/global.inc.php';
  19. $this_section = SECTION_PLATFORM_ADMIN;
  20. api_protect_admin_script();
  21. $action = isset($_GET['action']) ? $_GET['action'] : null;
  22. //Ajax request
  23. if (isset($_POST['sent_http_request'])) {
  24. if (isset($_POST['visibility']) &&
  25. $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 0) {
  26. if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
  27. if (SubLanguageManager::check_if_language_is_used($_POST['id']) == false) {
  28. SubLanguageManager::make_unavailable_language($_POST['id']);
  29. echo 'set_hidden';
  30. } else {
  31. echo 'confirm:'.intval($_POST['id']);
  32. }
  33. }
  34. }
  35. if (isset($_POST['visibility']) &&
  36. $_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 1
  37. ) {
  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. $msgLang = isset($_SESSION['disabled_languages']) ? 1 : 0;
  46. $disabledLang = isset($_SESSION['disabled_languages']) ? $_SESSION['disabled_languages'] : null;
  47. $htmlHeadXtra[] = '<script>
  48. $(function () {
  49. var msgLang = '.$msgLang.';
  50. var disabledLang = "'.$disabledLang.'"
  51. if (msgLang == 1) {
  52. $("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.get_lang('There are users currently using the following language. Please disable manually.').' <br /> " + disabledLang + "</div");
  53. }
  54. $("#disable_all_except_default").click(function () {
  55. if(confirm("'.get_lang('Please confirm your choice').'")) {
  56. $.ajax({
  57. contentType: "application/x-www-form-urlencoded",
  58. beforeSend: function(myObject) {
  59. $("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
  60. },
  61. type: "GET",
  62. url: "../admin/languages.php",
  63. data: "action=disable_all_except_default",
  64. success: function(datos) {
  65. window.location.href = "'.api_get_self().'";
  66. }
  67. });
  68. }
  69. return false;
  70. });
  71. //$(window).load(function () {
  72. $(".make_visible_and_invisible").attr("href","javascript:void(0)");
  73. //});
  74. $("td .make_visible_and_invisible").click(function () {
  75. make_visible="visible.png";
  76. make_invisible="invisible.png";
  77. id_link_tool=$(this).attr("id");
  78. id_img_link_tool="img"+id_link_tool;
  79. path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
  80. link_info_id=id_link_tool.split("linktool_");
  81. link_id=link_info_id[1];
  82. link_tool_info=path_name_of_imglinktool.split("/");
  83. my_image_tool=link_tool_info[link_tool_info.length-1];
  84. if (my_image_tool=="visible.png") {
  85. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
  86. my_visibility=0;
  87. } else {
  88. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
  89. my_visibility=1;
  90. }
  91. $.ajax({
  92. contentType: "application/x-www-form-urlencoded",
  93. beforeSend: function(myObject) {
  94. $("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
  95. },
  96. type: "POST",
  97. url: "../admin/languages.php",
  98. data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
  99. success: function(datos) {
  100. if (datos=="set_visible" || datos=="set_hidden") {
  101. $("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
  102. if (my_image_tool=="visible.png") {
  103. $("#"+id_img_link_tool).attr("alt","'.get_lang('Make available').'");
  104. $("#"+id_img_link_tool).attr("title","'.get_lang('Make available').'");
  105. } else {
  106. $("#"+id_img_link_tool).attr("alt","'.get_lang('Make unavailable').'");
  107. $("#"+id_img_link_tool).attr("title","'.get_lang('Make unavailable').'");
  108. }
  109. if (datos=="set_visible") {
  110. $("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('LanguageIsNowVisible').'</div>");
  111. }
  112. if (datos=="set_hidden") {
  113. $("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('The language has been hidden. It will not be possible to use it until it becomes visible again.').'</div>");
  114. }
  115. }
  116. var action = datos.split(":")[0];
  117. if (action && action == "confirm") {
  118. var id = datos.split(":")[1];
  119. var sure = "<div class=\"warning-message alert alert-warning\">'.get_lang('There are users using this language. Do you want to disable this language and set all this users with the default portal language?').'<br /><br /><a href=\"languages.php?action=make_unavailable_confirmed&id="+id+"\" class=\"btn btn-default\"><em class=\"fa fa-eye\"></em> '.get_lang('Make unavailable').'</a></div>";
  120. $("#id_content_message").html(sure);
  121. $("html, body").animate({ scrollTop: 0 }, 200);
  122. }
  123. } });
  124. });
  125. });
  126. </script>';
  127. // unset the msg session variable
  128. unset($_SESSION['disabled_languages']);
  129. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  130. $tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  131. $tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  132. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  133. $url = api_get_self();
  134. // we change the availability
  135. switch ($action) {
  136. case 'makeunavailable':
  137. if (!empty($id)) {
  138. SubLanguageManager::make_unavailable_language($id);
  139. Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
  140. }
  141. header("Location: $url");
  142. exit;
  143. break;
  144. case 'makeavailable':
  145. if (!empty($id)) {
  146. SubLanguageManager::make_available_language($id);
  147. Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
  148. }
  149. header("Location: $url");
  150. exit;
  151. case 'setplatformlanguage':
  152. if (!empty($id)) {
  153. SubLanguageManager::set_platform_language($id);
  154. Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
  155. }
  156. header("Location: $url");
  157. exit;
  158. case 'disable_all_except_default':
  159. $allLanguages = SubLanguageManager::getAllLanguages();
  160. $failedDisabledLanguages = '';
  161. $checkFailed = false;
  162. foreach ($allLanguages as $language) {
  163. if (SubLanguageManager::check_if_language_is_used($language['id']) == false) {
  164. SubLanguageManager::make_unavailable_language($language['id']);
  165. } else {
  166. if (intval(SubLanguageManager::get_platform_language_id()) !== intval($language['id'])) {
  167. $failedDisabledLanguages .= ' - '.$language['english_name'].'<br />';
  168. $checkFailed = true;
  169. }
  170. }
  171. }
  172. if ($checkFailed) {
  173. $_SESSION['disabled_languages'] = $failedDisabledLanguages;
  174. }
  175. Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
  176. header("Location: $url");
  177. exit;
  178. break;
  179. case 'make_unavailable_confirmed':
  180. $language_info = SubLanguageManager::get_all_information_of_language($id);
  181. if ($language_info['available'] == 1) {
  182. SubLanguageManager::make_unavailable_language($id);
  183. $platform_language = api_get_setting('platformLanguage');
  184. UserManager::update_all_user_languages($language_info['english_name'], $platform_language);
  185. Display::addFlash(Display::return_message(get_lang('The language has been hidden. It will not be possible to use it until it becomes visible again.'), 'confirm'));
  186. header("Location: $url");
  187. exit;
  188. }
  189. break;
  190. }
  191. if (isset($_POST['Submit']) && $_POST['Submit']) {
  192. // changing the name
  193. $name = Database::escape_string($_POST['txt_name']);
  194. $postId = (int) $_POST['edit_id'];
  195. $sql = "UPDATE $tbl_admin_languages SET original_name='$name'
  196. WHERE id='$postId'";
  197. $result = Database::query($sql);
  198. // changing the Platform language
  199. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] != '') {
  200. api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, api_get_current_access_url_id());
  201. header("Location: $url");
  202. exit;
  203. }
  204. } elseif (isset($_POST['action'])) {
  205. switch ($_POST['action']) {
  206. case 'makeavailable':
  207. if (count($_POST['id']) > 0) {
  208. $ids = [];
  209. foreach ($_POST['id'] as $index => $id) {
  210. $ids[] = intval($id);
  211. }
  212. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
  213. Database::query($sql);
  214. header("Location: $url");
  215. exit;
  216. }
  217. break;
  218. case 'makeunavailable':
  219. if (count($_POST['id']) > 0) {
  220. $ids = [];
  221. foreach ($_POST['id'] as $index => $id) {
  222. $ids[] = intval($id);
  223. }
  224. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  225. Database::query($sql);
  226. header("Location: $url");
  227. exit;
  228. }
  229. break;
  230. }
  231. }
  232. // setting the name of the tool
  233. $tool_name = get_lang('Chamilo Portal Languages');
  234. // setting breadcrumbs
  235. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  236. // displaying the explanation for this tool
  237. Display::addFlash(Display::return_message(get_lang('Chamilo Portal LanguagesExplanation'), 'normal'));
  238. // including the header file (which includes the banner itself)
  239. Display::display_header($tool_name);
  240. echo '<a id="disable_all_except_default" href="javascript:void(0)" class="btn btn-primary">
  241. <em class="fa fa-eye"></em> '.get_lang('Disable all languages except the platform default').'</a><br /><br />';
  242. // selecting all the languages
  243. $sql_select = "SELECT * FROM $tbl_admin_languages";
  244. $result_select = Database::query($sql_select);
  245. $currentLanguage = api_get_setting('language.platform_language');
  246. // the table data
  247. $language_data = [];
  248. while ($row = Database::fetch_array($result_select)) {
  249. $row_td = [];
  250. $row_td[] = $row['id'];
  251. $checked = '';
  252. // the first column is the original name of the language OR a form containing the original name
  253. if ($action == 'edit' && $row['id'] == $id) {
  254. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  255. $checked = ' checked="checked" ';
  256. }
  257. $row_td[] = '
  258. <input type="hidden" name="edit_id" value="'.$id.'" />
  259. <input type="text" name="txt_name" value="'.$row['original_name'].'" />
  260. <input type="checkbox" '.$checked.'name="platformlanguage" id="platformlanguage" value="'.$row['english_name'].'" />
  261. <label for="platformlanguage">'.$row['original_name'].' '.get_lang('as platformlanguage').'</label>
  262. <input type="submit" name="Submit" value="'.get_lang('Validate').'" />
  263. <a name="value" />';
  264. } else {
  265. $row_td[] = $row['original_name'];
  266. }
  267. // the second column
  268. $row_td[] = $row['english_name'].' ('.$row['isocode'].')';
  269. if ($row['isocode'] == $currentLanguage) {
  270. $setplatformlanguage = Display::return_icon(
  271. 'languages.png',
  272. get_lang('Current portal\'s language'),
  273. '',
  274. ICON_SIZE_SMALL
  275. );
  276. } else {
  277. $setplatformlanguage =
  278. "<a href=\"javascript:if (confirm('".addslashes(get_lang('Are you sure you want to set this language as the portal\'s default?'))."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">".
  279. Display::return_icon('languages_na.png', get_lang('Set language as default'), null, ICON_SIZE_SMALL)."</a>";
  280. }
  281. $allow_delete_sub_language = null;
  282. $allow_add_term_sub_language = null;
  283. $allow_use_sub_language = '';
  284. $allow_add_term_sub_language = '';
  285. if (api_get_setting('allow_use_sub_language') === 'true') {
  286. $verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
  287. if ($verified_if_is_sub_language === false) {
  288. $verified_if_is_father = SubLanguageManager::check_if_language_is_father($row['id']);
  289. $allow_use_sub_language = "&nbsp;<a href='sub_language_add.php?action=definenewsublanguage&id=".$row['id']."'>".
  290. Display::return_icon('new_language.png', get_lang('Create sub-language'), [], ICON_SIZE_SMALL)."</a>";
  291. if ($verified_if_is_father === true) {
  292. $allow_add_term_sub_language = '';
  293. } else {
  294. $allow_add_term_sub_language = '';
  295. }
  296. } else {
  297. $allow_use_sub_language = '';
  298. $all_information_of_sub_language = SubLanguageManager::get_all_information_of_language($row['id']);
  299. $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('Add terms to the sub-language'), ['width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL])."</a>";
  300. $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('Delete sub-language'), ['width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL])."</a>";
  301. }
  302. }
  303. if ($row['isocode'] == $currentLanguage) {
  304. $row_td[] = Display::return_icon('visible.png', get_lang('Visible')).
  305. "<a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".
  306. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL)."</a>
  307. &nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  308. } else {
  309. if ($row['available'] == 1) {
  310. $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeunavailable&id=".$row['id']."'>".
  311. Display::return_icon('visible.png', get_lang('Make unavailable'), ['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;
  312. } else {
  313. $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeavailable&id=".$row['id']."'>".
  314. Display::return_icon('invisible.png', get_lang('Make available'), ['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;
  315. }
  316. }
  317. $language_data[] = $row_td;
  318. }
  319. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  320. $table->set_header(0, '');
  321. $table->set_header(1, get_lang('Original name'));
  322. $table->set_header(2, get_lang('English name'));
  323. //$table->set_header(3, get_lang('Chamilo folder'));
  324. $table->set_header(4, get_lang('Properties'));
  325. $form_actions = [];
  326. $form_actions['makeavailable'] = get_lang('Make available');
  327. $form_actions['makeunavailable'] = get_lang('Make unavailable');
  328. $table->set_form_actions($form_actions);
  329. echo '<div id="id_content_message">&nbsp;</div>';
  330. $table->display();
  331. Display :: display_footer();