languages.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. // $Id: languages.php 18413 2009-02-10 18:51:52Z cvargas1 $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) Bart Mollet, Hogeschool Gent
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * This page allows the platform admin to decide which languages should
  22. * be available in the language selection menu in the login page. This can be
  23. * useful for countries with more than one official language (like Belgium:
  24. * Dutch, French and German) or international organisations that are active in
  25. * a limited number of countries.
  26. *
  27. * @author Patrick Cool, main author
  28. * @author Roan EMbrechts, code cleaning
  29. * @since Dokeos 1.6
  30. * @package dokeos.admin
  31. ==============================================================================
  32. */
  33. /*
  34. ==============================================================================
  35. INIT SECTION
  36. ==============================================================================
  37. */
  38. // name of the language file that needs to be included
  39. $language_file = 'admin';
  40. // we are in the admin area so we do not need a course id
  41. $cidReset = true;
  42. // include global script
  43. include ('../inc/global.inc.php');
  44. $this_section = SECTION_PLATFORM_ADMIN;
  45. api_protect_admin_script();
  46. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  47. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  48. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  49. /*
  50. ==============================================================================
  51. STORING THE CHANGES
  52. ==============================================================================
  53. */
  54. // we change the availability
  55. if ($_GET['action'] == 'makeunavailable')
  56. {
  57. $sql_make_unavailable = "UPDATE $tbl_admin_languages SET available='0' WHERE id='{$_GET['id']}'";
  58. $result = api_sql_query($sql_make_unavailable);
  59. }
  60. if ($_GET['action'] == 'makeavailable')
  61. {
  62. $sql_make_available = "UPDATE $tbl_admin_languages SET available='1' WHERE id='{$_GET['id']}'";
  63. $result = api_sql_query($sql_make_available);
  64. }
  65. if ($_GET['action'] == 'setplatformlanguage')
  66. {
  67. $sql_update = "SELECT english_name FROM ". $tbl_admin_languages." WHERE id='".$_GET['id']."'";
  68. $result = api_sql_query($sql_update,__FILE__,__LINE__);
  69. $lang=Database::fetch_array($result);
  70. $sql_update_2 = "UPDATE ".$tbl_settings_current." SET selected_value='".$lang['english_name']."' WHERE variable='platformLanguage'";
  71. $result_2 = api_sql_query($sql_update_2);
  72. }
  73. if ($_POST['Submit'])
  74. {
  75. // changing the name
  76. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  77. $result = api_sql_query($sql_update);
  78. // changing the Platform language
  79. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
  80. {
  81. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  82. //$result_2 = api_sql_query($sql_update_2);
  83. api_set_setting('platformLanguage',$_POST['platformlanguage'],null,null,$_configuration['access_url']);
  84. }
  85. }
  86. elseif (isset($_POST['action']))
  87. {
  88. switch ($_POST['action'])
  89. {
  90. case 'makeavailable' :
  91. if (count($_POST['id']) > 0)
  92. {
  93. $ids = array ();
  94. foreach ($_POST['id'] as $index => $id)
  95. {
  96. $ids[] = mysql_real_escape_string($id);
  97. }
  98. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
  99. api_sql_query($sql,__FILE__,__LINE__);
  100. }
  101. break;
  102. case 'makeunavailable' :
  103. if (count($_POST['id']) > 0)
  104. {
  105. $ids = array ();
  106. foreach ($_POST['id'] as $index => $id)
  107. {
  108. $ids[] = mysql_real_escape_string($id);
  109. }
  110. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  111. api_sql_query($sql,__FILE__,__LINE__);
  112. }
  113. break;
  114. }
  115. }
  116. /*
  117. ==============================================================================
  118. MAIN CODE
  119. ==============================================================================
  120. */
  121. // setting the name of the tool
  122. $tool_name = get_lang('PlatformLanguages');
  123. // setting breadcrumbs
  124. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  125. // including the header file (which includes the banner itself)
  126. Display :: display_header($tool_name);
  127. // displaying the naam of the tool
  128. //api_display_tool_title($tool_name);
  129. // displaying the explanation for this tool
  130. echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
  131. // selecting all the languages
  132. $sql_select = "SELECT * FROM $tbl_admin_languages";
  133. $result_select = api_sql_query($sql_select);
  134. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  135. $result_select_lang = api_sql_query($sql_select_lang,__FILE__,__LINE__);
  136. $row_lang=Database::fetch_array($result_select_lang);
  137. /*
  138. --------------------------------------
  139. DISPLAY THE TABLE
  140. --------------------------------------
  141. */
  142. // the table data
  143. $language_data = array ();
  144. while ($row = Database::fetch_array($result_select)) {
  145. $row_td = array ();
  146. $row_td[] = $row['id'];
  147. // the first column is the original name of the language OR a form containing the original name
  148. if ($_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  149. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  150. $checked = ' checked="checked" ';
  151. }
  152. $row_td[] = '<input type="hidden" name="edit_id" value="'.$_GET['id'].'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
  153. . '<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" />';
  154. } else {
  155. $row_td[] = $row['original_name'];
  156. }
  157. // the second column
  158. $row_td[] = $row['english_name'];
  159. // the third column
  160. $row_td[] = $row['dokeos_folder'];
  161. if ($row['english_name'] == $row_lang['selected_value']){
  162. $setplatformlanguage = Display::return_icon('links.gif', get_lang('CurrentLanguagesPortal'));
  163. } else {
  164. $setplatformlanguage = "<a href=\"javascript:if (confirm('".get_lang('AreYouSureYouWantToSetThisLanguageAsThePortalDefault')."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">".Display::return_icon('link_na.gif',get_lang('SetLanguageAsDefault'))."</a>";
  165. }
  166. if ($row['available'] == 1) {
  167. $row_td[] = "<a href='".api_get_self()."?action=makeunavailable&id=".$row['id']."'>".Display::return_icon('visible.gif', get_lang('MakeUnavailable'))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage;
  168. } else {
  169. $row_td[] = "<a href='".api_get_self()."?action=makeavailable&id=".$row['id']."'>".Display::return_icon('invisible.gif', get_lang('MakeAvailable'))."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.gif', get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage;
  170. }
  171. $language_data[] = $row_td;
  172. }
  173. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  174. $table->set_header(0, '');
  175. $table->set_header(1, get_lang('OriginalName'));
  176. $table->set_header(2, get_lang('EnglishName'));
  177. $table->set_header(3, get_lang('DokeosFolder'));
  178. $table->set_header(4, get_lang('Properties'));
  179. $form_actions = array ();
  180. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  181. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  182. $table->set_form_actions($form_actions);
  183. $table->display();
  184. /*
  185. ==============================================================================
  186. FOOTER
  187. ==============================================================================
  188. */
  189. Display :: display_footer();
  190. ?>