languages.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php // $Id: languages.php 19999 2009-04-23 00:14:09Z yannoo $
  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. include ('../inc/global.inc.php');
  28. $this_section = SECTION_PLATFORM_ADMIN;
  29. api_protect_admin_script();
  30. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  31. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  32. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  33. /*
  34. ==============================================================================
  35. STORING THE CHANGES
  36. ==============================================================================
  37. */
  38. // we change the availability
  39. if ($_GET['action'] == 'makeunavailable')
  40. {
  41. $sql_make_unavailable = "UPDATE $tbl_admin_languages SET available='0' WHERE id='{$_GET['id']}'";
  42. $result = api_sql_query($sql_make_unavailable);
  43. }
  44. if ($_GET['action'] == 'makeavailable')
  45. {
  46. $sql_make_available = "UPDATE $tbl_admin_languages SET available='1' WHERE id='{$_GET['id']}'";
  47. $result = api_sql_query($sql_make_available);
  48. }
  49. if ($_GET['action'] == 'setplatformlanguage')
  50. {
  51. $sql_update = "SELECT english_name FROM ". $tbl_admin_languages." WHERE id='".$_GET['id']."'";
  52. $result = api_sql_query($sql_update,__FILE__,__LINE__);
  53. $lang=Database::fetch_array($result);
  54. $sql_update_2 = "UPDATE ".$tbl_settings_current." SET selected_value='".$lang['english_name']."' WHERE variable='platformLanguage'";
  55. $result_2 = api_sql_query($sql_update_2);
  56. }
  57. if ($_POST['Submit'])
  58. {
  59. // changing the name
  60. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  61. $result = api_sql_query($sql_update);
  62. // changing the Platform language
  63. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
  64. {
  65. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  66. //$result_2 = api_sql_query($sql_update_2);
  67. api_set_setting('platformLanguage',$_POST['platformlanguage'],null,null,$_configuration['access_url']);
  68. }
  69. }
  70. elseif (isset($_POST['action']))
  71. {
  72. switch ($_POST['action'])
  73. {
  74. case 'makeavailable' :
  75. if (count($_POST['id']) > 0)
  76. {
  77. $ids = array ();
  78. foreach ($_POST['id'] as $index => $id)
  79. {
  80. $ids[] = mysql_real_escape_string($id);
  81. }
  82. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
  83. api_sql_query($sql,__FILE__,__LINE__);
  84. }
  85. break;
  86. case 'makeunavailable' :
  87. if (count($_POST['id']) > 0)
  88. {
  89. $ids = array ();
  90. foreach ($_POST['id'] as $index => $id)
  91. {
  92. $ids[] = mysql_real_escape_string($id);
  93. }
  94. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  95. api_sql_query($sql,__FILE__,__LINE__);
  96. }
  97. break;
  98. }
  99. }
  100. /*
  101. ==============================================================================
  102. MAIN CODE
  103. ==============================================================================
  104. */
  105. // setting the name of the tool
  106. $tool_name = get_lang('PlatformLanguages');
  107. // setting breadcrumbs
  108. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  109. // including the header file (which includes the banner itself)
  110. Display :: display_header($tool_name);
  111. // displaying the naam of the tool
  112. //api_display_tool_title($tool_name);
  113. // displaying the explanation for this tool
  114. echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
  115. // selecting all the languages
  116. $sql_select = "SELECT * FROM $tbl_admin_languages";
  117. $result_select = api_sql_query($sql_select);
  118. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  119. $result_select_lang = api_sql_query($sql_select_lang,__FILE__,__LINE__);
  120. $row_lang=Database::fetch_array($result_select_lang);
  121. /*
  122. --------------------------------------
  123. DISPLAY THE TABLE
  124. --------------------------------------
  125. */
  126. // the table data
  127. $language_data = array ();
  128. while ($row = Database::fetch_array($result_select)) {
  129. $row_td = array ();
  130. $row_td[] = $row['id'];
  131. // the first column is the original name of the language OR a form containing the original name
  132. if ($_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  133. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  134. $checked = ' checked="checked" ';
  135. }
  136. $row_td[] = '<input type="hidden" name="edit_id" value="'.$_GET['id'].'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
  137. . '<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" />';
  138. } else {
  139. $row_td[] = $row['original_name'];
  140. }
  141. // the second column
  142. $row_td[] = $row['english_name'];
  143. // the third column
  144. $row_td[] = $row['dokeos_folder'];
  145. if ($row['english_name'] == $row_lang['selected_value']){
  146. $setplatformlanguage = Display::return_icon('links.gif', get_lang('CurrentLanguagesPortal'));
  147. } else {
  148. $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>";
  149. }
  150. if ($row['available'] == 1) {
  151. $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;
  152. } else {
  153. $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;
  154. }
  155. $language_data[] = $row_td;
  156. }
  157. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  158. $table->set_header(0, '');
  159. $table->set_header(1, get_lang('OriginalName'));
  160. $table->set_header(2, get_lang('EnglishName'));
  161. $table->set_header(3, get_lang('DokeosFolder'));
  162. $table->set_header(4, get_lang('Properties'));
  163. $form_actions = array ();
  164. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  165. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  166. $table->set_form_actions($form_actions);
  167. $table->display();
  168. /*
  169. ==============================================================================
  170. FOOTER
  171. ==============================================================================
  172. */
  173. Display :: display_footer();
  174. ?>