languages.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  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 dokeos.admin
  15. ==============================================================================
  16. */
  17. /*
  18. ==============================================================================
  19. INIT SECTION
  20. ==============================================================================
  21. */
  22. // name of the language file that needs to be included
  23. $language_file = 'admin';
  24. // we are in the admin area so we do not need a course id
  25. $cidReset = true;
  26. // include global script
  27. require_once '../inc/global.inc.php';
  28. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  29. require_once 'sub_language.class.php';
  30. $this_section = SECTION_PLATFORM_ADMIN;
  31. api_protect_admin_script();
  32. //Ajax request
  33. if (isset($_POST['sent_http_request'])) {
  34. if (isset($_POST['visibility']) && $_POST['visibility']==strval(intval($_POST['visibility'])) && $_POST['visibility']==0) {
  35. if (isset($_POST['id'])&& $_POST['id']==strval(intval($_POST['id']))) {
  36. SubLanguageManager::make_unavailable_language($_POST['id']);
  37. echo 'set_hidden';
  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 src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  49. $htmlHeadXtra[] ='<script type="text/javascript">
  50. $(document).ready(function() {
  51. //$(window).load(function () {
  52. $(".make_visible_and_invisible").attr("href","javascript:void(0)");
  53. //});
  54. $("td .make_visible_and_invisible").click(function () {
  55. make_visible="visible.gif";
  56. make_invisible="invisible.gif";
  57. id_link_tool=$(this).attr("id");
  58. id_img_link_tool="img"+id_link_tool;
  59. path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
  60. link_info_id=id_link_tool.split("linktool_");
  61. link_id=link_info_id[1];
  62. link_tool_info=path_name_of_imglinktool.split("/");
  63. my_image_tool=link_tool_info[link_tool_info.length-1];
  64. if (my_image_tool=="visible.gif") {
  65. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
  66. my_visibility=0;
  67. } else {
  68. path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
  69. my_visibility=1;
  70. }
  71. $.ajax({
  72. contentType: "application/x-www-form-urlencoded",
  73. beforeSend: function(objeto) {
  74. $("#id_content_message").html("<div class=\"normal-message\"><img src=\'/main/inc/lib/javascript/indicator.gif\' /></div>");
  75. },
  76. type: "POST",
  77. url: "../admin/languages.php",
  78. data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
  79. success: function(datos) {
  80. $("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
  81. if (my_image_tool=="visible.gif") {
  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. } else {
  91. $("#id_content_message").html("<div class=\"confirmation-message\">'.get_lang('LanguageIsNowHidden', '').'</div>");
  92. }
  93. } });
  94. });
  95. });
  96. </script>';
  97. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  98. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  99. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  100. /*
  101. ==============================================================================
  102. STORING THE CHANGES
  103. ==============================================================================
  104. */
  105. // we change the availability
  106. if ($_GET['action'] == 'makeunavailable') {
  107. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  108. SubLanguageManager::make_unavailable_language($_GET['id']);
  109. }
  110. }
  111. if ($_GET['action'] == 'makeavailable') {
  112. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  113. SubLanguageManager::make_available_language($_GET['id']);
  114. }
  115. }
  116. if ($_GET['action'] == 'setplatformlanguage') {
  117. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  118. SubLanguageManager::set_platform_language($_GET['id']);
  119. }
  120. }
  121. if ($_POST['Submit'])
  122. {
  123. // changing the name
  124. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  125. $result = Database::query($sql_update);
  126. // changing the Platform language
  127. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
  128. {
  129. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  130. //$result_2 = Database::query($sql_update_2);
  131. api_set_setting('platformLanguage',$_POST['platformlanguage'],null,null,$_configuration['access_url']);
  132. }
  133. }
  134. elseif (isset($_POST['action']))
  135. {
  136. switch ($_POST['action'])
  137. {
  138. case 'makeavailable' :
  139. if (count($_POST['id']) > 0)
  140. {
  141. $ids = array ();
  142. foreach ($_POST['id'] as $index => $id)
  143. {
  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. {
  153. $ids = array ();
  154. foreach ($_POST['id'] as $index => $id)
  155. {
  156. $ids[] = Database::escape_string($id);
  157. }
  158. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  159. Database::query($sql);
  160. }
  161. break;
  162. }
  163. }
  164. /*
  165. ==============================================================================
  166. MAIN CODE
  167. ==============================================================================
  168. */
  169. // setting the name of the tool
  170. $tool_name = get_lang('PlatformLanguages');
  171. // setting breadcrumbs
  172. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  173. // including the header file (which includes the banner itself)
  174. Display :: display_header($tool_name);
  175. // displaying the naam of the tool
  176. //api_display_tool_title($tool_name);
  177. // displaying the explanation for this tool
  178. echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
  179. // selecting all the languages
  180. $sql_select = "SELECT * FROM $tbl_admin_languages";
  181. $result_select = Database::query($sql_select);
  182. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  183. $result_select_lang = Database::query($sql_select_lang);
  184. $row_lang=Database::fetch_array($result_select_lang);
  185. /*
  186. --------------------------------------
  187. DISPLAY THE TABLE
  188. --------------------------------------
  189. */
  190. // the table data
  191. $language_data = array ();
  192. while ($row = Database::fetch_array($result_select)) {
  193. $row_td = array ();
  194. $row_td[] = $row['id'];
  195. // the first column is the original name of the language OR a form containing the original name
  196. if ($_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  197. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  198. $checked = ' checked="checked" ';
  199. }
  200. $row_td[] = '<input type="hidden" name="edit_id" value="'.Security::remove_XSS($_GET['id']).'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
  201. . '<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" />';
  202. } else {
  203. $row_td[] = $row['original_name'];
  204. }
  205. // the second column
  206. $row_td[] = $row['english_name'];
  207. // the third column
  208. $row_td[] = $row['dokeos_folder'];
  209. if ($row['english_name'] == $row_lang['selected_value']){
  210. $setplatformlanguage = Display::return_icon('links.gif', get_lang('CurrentLanguagesPortal'));
  211. } else {
  212. $setplatformlanguage = "<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureYouWantToSetThisLanguageAsThePortalDefault'))."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">".Display::return_icon('link_na.gif',get_lang('SetLanguageAsDefault'))."</a>";
  213. }
  214. if (api_get_setting('allow_use_sub_language')=='true') {
  215. $verified_if_is_sub_language=SubLanguageManager::check_if_language_is_sub_language($row['id']);
  216. if ($verified_if_is_sub_language===false) {
  217. $verified_if_is_father=SubLanguageManager::check_if_language_is_father($row['id']);
  218. $allow_use_sub_language = "&nbsp;<a href='sub_language_add.php?action=definenewsublanguage&id=".$row['id']."'>".Display::return_icon('mas.gif', get_lang('CreateSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
  219. if ($verified_if_is_father===true) {
  220. //$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'=>'22','height'=>'22'))."</a>";
  221. $allow_add_term_sub_language='';
  222. } else {
  223. $allow_add_term_sub_language='';
  224. }
  225. } else {
  226. $allow_use_sub_language='';
  227. $all_information_of_sub_language=SubLanguageManager::get_all_information_of_language($row['id']);
  228. $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'=>'22','height'=>'22'))."</a>";
  229. $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_data.gif', get_lang('DeleteSubLanguage'),array('width'=>'22','height'=>'22'))."</a>";
  230. }
  231. } else {
  232. $allow_use_sub_language='';
  233. $allow_add_term_sub_language='';
  234. }
  235. if ($row['available'] == 1) {
  236. $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.gif', get_lang('MakeUnavailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  237. //$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('visible.gif', get_lang('MakeUnavailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
  238. } else {
  239. $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.gif', get_lang('MakeAvailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  240. //$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='javascript:void(0)'>".Display::return_icon('invisible.gif', get_lang('MakeAvailable'),array('id'=>'imglinktool_'.$row['id']))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language;
  241. }
  242. $language_data[] = $row_td;
  243. }
  244. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  245. $table->set_header(0, '');
  246. $table->set_header(1, get_lang('OriginalName'));
  247. $table->set_header(2, get_lang('EnglishName'));
  248. $table->set_header(3, get_lang('DokeosFolder'));
  249. $table->set_header(4, get_lang('Properties'));
  250. $form_actions = array ();
  251. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  252. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  253. $table->set_form_actions($form_actions);
  254. echo '<div id="id_content_message">&nbsp;</div>';
  255. $table->display();
  256. /*
  257. ==============================================================================
  258. FOOTER
  259. ==============================================================================
  260. */
  261. Display :: display_footer();
  262. ?>