languages.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 type="text/javascript">
  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=\'/main/inc/lib/javascript/indicator.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. $("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
  80. if (my_image_tool=="visible.png") {
  81. $("#"+id_img_link_tool).attr("alt","'.get_lang('MakeAvailable', '').'");
  82. $("#"+id_img_link_tool).attr("title","'.get_lang('MakeAvailable', '').'");
  83. } else {
  84. $("#"+id_img_link_tool).attr("alt","'.get_lang('MakeUnavailable', '').'");
  85. $("#"+id_img_link_tool).attr("title","'.get_lang('MakeUnavailable', '').'");
  86. }
  87. if (datos=="set_visible") {
  88. $("#id_content_message").html("<div class=\"confirmation-message\">'.get_lang('LanguageIsNowVisible', '').'</div>");
  89. } else {
  90. $("#id_content_message").html("<div class=\"confirmation-message\">'.get_lang('LanguageIsNowHidden', '').'</div>");
  91. }
  92. } });
  93. });
  94. });
  95. </script>';
  96. // setting the table that is needed for the styles management (there is a check if it exists later in this code)
  97. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  98. $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  99. /*
  100. ==============================================================================
  101. STORING THE CHANGES
  102. ==============================================================================
  103. */
  104. // we change the availability
  105. if ($_GET['action'] == 'makeunavailable') {
  106. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  107. SubLanguageManager::make_unavailable_language($_GET['id']);
  108. }
  109. }
  110. if ($_GET['action'] == 'makeavailable') {
  111. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  112. SubLanguageManager::make_available_language($_GET['id']);
  113. }
  114. }
  115. if ($_GET['action'] == 'setplatformlanguage') {
  116. if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
  117. SubLanguageManager::set_platform_language($_GET['id']);
  118. }
  119. }
  120. if ($_POST['Submit'])
  121. {
  122. // changing the name
  123. $sql_update = "UPDATE $tbl_admin_languages SET original_name='{$_POST['txt_name']}' WHERE id='{$_POST['edit_id']}'";
  124. $result = Database::query($sql_update);
  125. // changing the Platform language
  126. if ($_POST['platformlanguage'] && $_POST['platformlanguage'] <> '')
  127. {
  128. //$sql_update_2 = "UPDATE $tbl_settings_current SET selected_value='{$_POST['platformlanguage']}' WHERE variable='platformLanguage'";
  129. //$result_2 = Database::query($sql_update_2);
  130. api_set_setting('platformLanguage',$_POST['platformlanguage'],null,null,$_configuration['access_url']);
  131. }
  132. }
  133. elseif (isset($_POST['action']))
  134. {
  135. switch ($_POST['action'])
  136. {
  137. case 'makeavailable' :
  138. if (count($_POST['id']) > 0)
  139. {
  140. $ids = array ();
  141. foreach ($_POST['id'] as $index => $id)
  142. {
  143. $ids[] = Database::escape_string($id);
  144. }
  145. $sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
  146. Database::query($sql);
  147. }
  148. break;
  149. case 'makeunavailable' :
  150. if (count($_POST['id']) > 0)
  151. {
  152. $ids = array ();
  153. foreach ($_POST['id'] as $index => $id)
  154. {
  155. $ids[] = Database::escape_string($id);
  156. }
  157. $sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
  158. Database::query($sql);
  159. }
  160. break;
  161. }
  162. }
  163. /*
  164. ==============================================================================
  165. MAIN CODE
  166. ==============================================================================
  167. */
  168. // setting the name of the tool
  169. $tool_name = get_lang('PlatformLanguages');
  170. // setting breadcrumbs
  171. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  172. // including the header file (which includes the banner itself)
  173. Display :: display_header($tool_name);
  174. // displaying the naam of the tool
  175. //api_display_tool_title($tool_name);
  176. // displaying the explanation for this tool
  177. echo '<p>'.get_lang('PlatformLanguagesExplanation').'</p>';
  178. // selecting all the languages
  179. $sql_select = "SELECT * FROM $tbl_admin_languages";
  180. $result_select = Database::query($sql_select);
  181. $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
  182. $result_select_lang = Database::query($sql_select_lang);
  183. $row_lang=Database::fetch_array($result_select_lang);
  184. /*
  185. --------------------------------------
  186. DISPLAY THE TABLE
  187. --------------------------------------
  188. */
  189. // the table data
  190. $language_data = array ();
  191. while ($row = Database::fetch_array($result_select)) {
  192. $row_td = array ();
  193. $row_td[] = $row['id'];
  194. // the first column is the original name of the language OR a form containing the original name
  195. if ($_GET['action'] == 'edit' and $row['id'] == $_GET['id']) {
  196. if ($row['english_name'] == api_get_setting('platformLanguage')) {
  197. $checked = ' checked="checked" ';
  198. }
  199. $row_td[] = '<input type="hidden" name="edit_id" value="'.Security::remove_XSS($_GET['id']).'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
  200. . '<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" />';
  201. } else {
  202. $row_td[] = $row['original_name'];
  203. }
  204. // the second column
  205. $row_td[] = $row['english_name'];
  206. // the third column
  207. $row_td[] = $row['dokeos_folder'];
  208. if ($row['english_name'] == $row_lang['selected_value']){
  209. $setplatformlanguage = Display::return_icon('languages.png', get_lang('CurrentLanguagesPortal'),'',22);
  210. } else {
  211. $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'),'',22)."</a>";
  212. }
  213. if (api_get_setting('allow_use_sub_language')=='true') {
  214. $verified_if_is_sub_language=SubLanguageManager::check_if_language_is_sub_language($row['id']);
  215. if ($verified_if_is_sub_language===false) {
  216. $verified_if_is_father=SubLanguageManager::check_if_language_is_father($row['id']);
  217. $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(),22)."</a>";
  218. if ($verified_if_is_father===true) {
  219. //$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>";
  220. $allow_add_term_sub_language='';
  221. } else {
  222. $allow_add_term_sub_language='';
  223. }
  224. } else {
  225. $allow_use_sub_language='';
  226. $all_information_of_sub_language=SubLanguageManager::get_all_information_of_language($row['id']);
  227. $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>";
  228. $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'=>'22','height'=>'22'))."</a>";
  229. }
  230. } else {
  231. $allow_use_sub_language='';
  232. $allow_add_term_sub_language='';
  233. }
  234. if ($row['available'] == 1) {
  235. $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']),22)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  236. //$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;
  237. } else {
  238. $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']),22)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
  239. //$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;
  240. }
  241. $language_data[] = $row_td;
  242. }
  243. $table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
  244. $table->set_header(0, '');
  245. $table->set_header(1, get_lang('OriginalName'));
  246. $table->set_header(2, get_lang('EnglishName'));
  247. $table->set_header(3, get_lang('DokeosFolder'));
  248. $table->set_header(4, get_lang('Properties'));
  249. $form_actions = array ();
  250. $form_actions['makeavailable'] = get_lang('MakeAvailable');
  251. $form_actions['makeunavailable'] = get_lang('MakeUnavailable');
  252. $table->set_form_actions($form_actions);
  253. echo '<div id="id_content_message">&nbsp;</div>';
  254. $table->display();
  255. /*
  256. ==============================================================================
  257. FOOTER
  258. ==============================================================================
  259. */
  260. Display :: display_footer();
  261. ?>