tool_navigation_menu.inc.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Navigation menu display code
  5. *
  6. * @package dokeos.include
  7. */
  8. require_once api_get_path(LIBRARY_PATH).'course_home.lib.php'; // For using the method CourseHome::translate_tool_name();
  9. define('SHORTCUTS_HORIZONTAL', 0);
  10. define('SHORTCUTS_VERTICAL', 1);
  11. /**
  12. * Build the navigation items to show in a course menu
  13. * @param boolean $include_admin_tools
  14. */
  15. function get_navigation_items($include_admin_tools = false) {
  16. global $is_courseMember;
  17. global $_user;
  18. global $_course;
  19. if (!empty($_course['db_name'])) {
  20. $database = $_course['db_name'];
  21. }
  22. $navigation_items = array ();
  23. $course_id = api_get_course_id();
  24. if (!empty($course_id) && $course_id != -1) {
  25. $user_id = api_get_user_id();
  26. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST, $database);
  27. /* Link to the Course homepage */
  28. $navigation_items['home']['image'] = 'home.gif';
  29. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php';
  30. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  31. /* Link to the different tools */
  32. $sql_menu_query = "SELECT * FROM $course_tools_table WHERE visibility='1' and admin='0' ORDER BY id ASC";
  33. $sql_result = Database::query($sql_menu_query);
  34. while ($row = Database::fetch_array($sql_result)) {
  35. $navigation_items[$row['id']] = $row;
  36. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  37. $navigation_items[$row['id']]['link'] = api_get_path(REL_CODE_PATH).$row['link'];
  38. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  39. }
  40. }
  41. /* Admin (edit rights) only links
  42. - Course settings (course admin only)
  43. - Course rights (roles & rights overview) */
  44. if ($include_admin_tools) {
  45. $course_settings_sql = "SELECT name,image FROM $course_tools_table
  46. WHERE link='course_info/infocours.php'";
  47. $sql_result = Database::query($course_settings_sql);
  48. $course_setting_info = Database::fetch_array($sql_result);
  49. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  50. if (api_get_session_id() == 0) {
  51. // course settings item
  52. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  53. $navigation_items['course_settings']['link'] = api_get_path(REL_CODE_PATH).'course_info/infocours.php';
  54. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  55. }
  56. }
  57. }
  58. foreach ($navigation_items as $key => $navigation_item) {
  59. if (strstr($navigation_item['link'], '?')) {
  60. //link already contains a parameter, add course id parameter with &
  61. $parameter_separator = '&amp;';
  62. } else {
  63. //link doesn't contain a parameter yet, add course id parameter with ?
  64. $parameter_separator = '?';
  65. }
  66. $navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  67. }
  68. return $navigation_items;
  69. }
  70. /**
  71. * Show a navigation menu
  72. */
  73. function show_navigation_menu() {
  74. $navigation_items = get_navigation_items(true);
  75. $course_id = api_get_course_id();
  76. if (api_get_setting('show_navigation_menu') == 'icons') {
  77. echo '<div style="float:right;width: 40px;position:absolute;right:10px;top:10px;">';
  78. show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  79. echo '</div>';
  80. } else {
  81. echo '<div id="toolnav"> <!-- start of #toolnav -->';
  82. ?>
  83. <script type="text/javascript">
  84. /* <![CDATA[ */
  85. function createCookie(name, value, days)
  86. {
  87. if (days)
  88. {
  89. var date = new Date();
  90. date.setTime(date.getTime()+(days*24*60*60*1000));
  91. var expires = "; expires="+date.toGMTString();
  92. }
  93. else var expires = "";
  94. document.cookie = name+"="+value+expires+"; path=/";
  95. }
  96. function readCookie(name)
  97. {
  98. var nameEQ = name + "=";
  99. var ca = document.cookie.split(';');
  100. for (var i = 0; i < ca.length; i++)
  101. {
  102. var c = ca[i];
  103. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  104. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  105. }
  106. return null;
  107. }
  108. function swap_menu()
  109. {
  110. toolnavlist_el = document.getElementById('toolnavlist');
  111. center_el = document.getElementById('center');
  112. swap_menu_link_el = document.getElementById('swap_menu_link');
  113. if (toolnavlist_el.style.display == 'none')
  114. {
  115. toolnavlist_el.style.display = '';
  116. if (center_el)
  117. {
  118. center_el.style.margin = '0 190px 0 0';
  119. }
  120. swap_menu_link_el.innerHTML = '<?php echo get_lang('Hide'); ?> &raquo;&raquo;';
  121. createCookie('dokeos_menu_state',1,10);
  122. }
  123. else
  124. {
  125. toolnavlist_el.style.display = 'none';
  126. if (center_el)
  127. {
  128. center_el.style.margin = '0 0 0 0';
  129. }
  130. swap_menu_link_el.innerHTML = '&laquo;&laquo; <?php echo get_lang('Show'); ?>';
  131. createCookie('dokeos_menu_state',0,10);
  132. }
  133. }
  134. document.write('<a href="javascript: void(0);" id="swap_menu_link" onclick="javascript: swap_menu();"><?php echo get_lang('Hide'); ?> &raquo;&raquo;<\/a>');
  135. /* ]]> */
  136. </script>
  137. <?php
  138. echo '<div id="toolnavbox">';
  139. echo '<div id="toolnavlist"><dl>';
  140. foreach ($navigation_items as $key => $navigation_item) {
  141. //students can't see the course settings option
  142. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  143. continue;
  144. }
  145. echo '<dd>';
  146. $url_item = parse_url($navigation_item['link']);
  147. $url_current = parse_url($_SERVER['REQUEST_URI']);
  148. if (strpos($navigation_item['link'], 'chat') !== false && api_get_course_setting('allow_open_chat_window', $course_id)) {
  149. echo '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $navigation_item['target'] . '"';
  150. } else {
  151. echo '<a href="'.$navigation_item['link'].'" target="_top" ';
  152. }
  153. if (stristr($url_item['path'], $url_current['path'])) {
  154. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'],'learnpath_id='.$_GET['learnpath_id']) === 0) {
  155. echo ' id="here"';
  156. }
  157. }
  158. echo ' title="'.$navigation_item['name'].'">';
  159. if (api_get_setting('show_navigation_menu') != 'text') {
  160. echo '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  161. }
  162. if (api_get_setting('show_navigation_menu') != 'icons') {
  163. echo $navigation_item['name'];
  164. }
  165. echo '</a>';
  166. echo '</dd>';
  167. echo "\n";
  168. }
  169. echo '</dl></div></div>';
  170. echo '</div> <!-- end "#toolnav" -->';
  171. ?>
  172. <script type="text/javascript">
  173. /* <![CDATA[ */
  174. if (readCookie('dokeos_menu_state') == 0)
  175. swap_menu();
  176. }
  177. /* ]]> */
  178. </script>
  179. <?php
  180. }
  181. }
  182. /**
  183. * Show a toolbar with shortcuts to the course tool
  184. */
  185. function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL) {
  186. $navigation_items = get_navigation_items(false);
  187. foreach ($navigation_items as $key => $navigation_item) {
  188. if (strpos($navigation_item['link'],'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  189. echo '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $navigation_item['target'] . '"';
  190. } else {
  191. echo '<a href="'.$navigation_item['link'].'"';
  192. }
  193. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  194. echo ' id="here"';
  195. }
  196. echo ' target="_top" title="'.$navigation_item['name'].'">';
  197. echo '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  198. echo '</a>';
  199. if ($orientation == SHORTCUTS_VERTICAL) {
  200. echo '<br />';
  201. }
  202. }
  203. }