languages.php 14 KB

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