tool_navigation_menu.inc.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. // $Id: tool_navigation_menu.inc.php 9319 2006-10-04 12:31:07Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2005 Dokeos S.A.
  7. Copyright (c) 2004-2005 Sandra Mathijs, Hogeschool Gent
  8. Copyright (c) 2005 Roan Embrechts, Vrije Universiteit Brussel
  9. Copyright (c) 2005 Wolfgang Schneider
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  19. Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. * Navigation menu display code
  25. *
  26. * @package dokeos.include
  27. ==============================================================================
  28. */
  29. define('SHORTCUTS_HORIZONTAL',0);
  30. define('SHORTCUTS_VERTICAL',1);
  31. /**
  32. * Build the navigation items to show in a course menu
  33. * @param boolean $include_admin_tools
  34. */
  35. function get_navigation_items($include_admin_tools = false)
  36. {
  37. global $is_courseMember;
  38. $navigation_items = array ();
  39. $course_id = api_get_course_id();
  40. if (isset ($course_id))
  41. {
  42. $user_id = api_get_user_id();
  43. $course_tools_table = Database :: get_course_table(TOOL_LIST_TABLE);
  44. /*
  45. --------------------------------------------------------------
  46. Link to the Course homepage
  47. --------------------------------------------------------------
  48. */
  49. $navigation_items['home']['image'] = 'home.gif';
  50. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).$_SESSION['_course']['path'].'/index.php';
  51. $navigation_items['home']['name'] = get_lang("CourseHomepageLink");
  52. /*
  53. --------------------------------------------------------------
  54. Link to the different tools
  55. --------------------------------------------------------------
  56. */
  57. $sql_menu_query = "SELECT * FROM $course_tools_table WHERE visibility='1' and admin='0' ORDER BY id ASC";
  58. $sql_result = api_sql_query($sql_menu_query, __FILE__, __LINE__);
  59. while ($row = mysql_fetch_array($sql_result))
  60. {
  61. $navigation_items[$row['id']] = $row;
  62. if (!stristr($row['link'], 'http://'))
  63. {
  64. $navigation_items[$row['id']]['link'] = api_get_path(REL_CLARO_PATH).$row['link'];
  65. $navigation_items[$row['id']]['name'] = $row['image'] == 'scormbuilder.gif' ? $navigation_items[$row['id']]['name'] : get_lang($navigation_items[$row['id']]['name']);
  66. }
  67. }
  68. /*
  69. --------------------------------------------------------------
  70. Admin (edit rights) only links
  71. - Course settings (course admin only)
  72. - Course rights (roles & rights overview)
  73. --------------------------------------------------------------
  74. */
  75. if ($include_admin_tools)
  76. {
  77. $course_settings_sql = " SELECT name,image FROM $course_tools_table
  78. WHERE link='course_info/infocours.php'";
  79. $sql_result = api_sql_query($course_settings_sql);
  80. $course_setting_info = mysql_fetch_array($sql_result);
  81. $course_setting_visual_name = get_lang($course_setting_info['name']);
  82. // course settings item
  83. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  84. $navigation_items['course_settings']['link'] = api_get_path(REL_CLARO_PATH).'course_info/infocours.php';
  85. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  86. }
  87. }
  88. foreach($navigation_items as $key => $navigation_item)
  89. {
  90. if (strstr($navigation_item['link'], '?'))
  91. {
  92. //link already contains a parameter, add course id parameter with &
  93. $parameter_separator = '&amp;';
  94. }
  95. else
  96. {
  97. //link doesn't contain a parameter yet, add course id parameter with ?
  98. $parameter_separator = '?';
  99. }
  100. $navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  101. }
  102. return $navigation_items;
  103. }
  104. /**
  105. * Show a navigation menu
  106. */
  107. function show_navigation_menu()
  108. {
  109. $navigation_items = get_navigation_items(true);
  110. if(api_get_setting('show_navigation_menu') == 'icons')
  111. {
  112. echo '<div style="float:right;width: 40px;position:absolute;right:10px;top:10px;">';
  113. show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  114. echo '</div>';
  115. }
  116. else
  117. {
  118. echo '<div id="toolnav"> <!-- start of #toolnav -->';
  119. ?>
  120. <script type="text/javascript">
  121. /* <![CDATA[ */
  122. function createCookie(name,value,days)
  123. {
  124. if (days)
  125. {
  126. var date = new Date();
  127. date.setTime(date.getTime()+(days*24*60*60*1000));
  128. var expires = "; expires="+date.toGMTString();
  129. }
  130. else var expires = "";
  131. document.cookie = name+"="+value+expires+"; path=/";
  132. }
  133. function readCookie(name)
  134. {
  135. var nameEQ = name + "=";
  136. var ca = document.cookie.split(';');
  137. for(var i=0;i < ca.length;i++)
  138. {
  139. var c = ca[i];
  140. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  141. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  142. }
  143. return null;
  144. }
  145. function swap_menu()
  146. {
  147. toolnavlist = document.getElementById('toolnavlist');
  148. center = document.getElementById('center');
  149. swap_menu_link = document.getElementById('swap_menu_link');
  150. if(toolnavlist.style.display == 'none')
  151. {
  152. toolnavlist.style.display = '';
  153. center.style.margin = '0 190px 0 0';
  154. swap_menu_link.innerHTML = '<?php echo get_lang('Hide'); ?> &raquo;&raquo;';
  155. createCookie('dokeos_menu_state',1,10);
  156. }
  157. else
  158. {
  159. toolnavlist.style.display = 'none';
  160. center.style.margin = '0 0 0 0';
  161. swap_menu_link.innerHTML = '&laquo;&laquo; <?php echo get_lang('Show'); ?>';
  162. createCookie('dokeos_menu_state',0,10);
  163. }
  164. }
  165. document.write('<a href="#" id="swap_menu_link" onclick="swap_menu();" style="float:right;"><?php echo get_lang('Hide'); ?> &raquo;&raquo;<\/a>');
  166. /* ]]> */
  167. </script>
  168. <?php
  169. echo '<div id="toolnavbox">';
  170. echo '<div id="toolnavlist"><dl>';
  171. foreach ($navigation_items as $key => $navigation_item)
  172. {
  173. echo '<dd>';
  174. $url_item = parse_url($navigation_item['link']);
  175. $url_current = parse_url($_SERVER['REQUEST_URI']);
  176. echo '<a href="'.$navigation_item['link'].'"';
  177. if (stristr($url_item['path'],$url_current['path']))
  178. {
  179. if(! isset($_GET['learnpath_id']) || strpos($url_item['query'],'learnpath_id='.$_GET['learnpath_id']) === 0)
  180. {
  181. echo ' id="here"';
  182. }
  183. }
  184. echo ' title="'.$navigation_item['name'].'">';
  185. if (api_get_setting('show_navigation_menu') != 'textonly')
  186. {
  187. echo '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  188. }
  189. if (api_get_setting('show_navigation_menu') != 'icons')
  190. {
  191. echo $navigation_item['name'];
  192. }
  193. echo '</a>';
  194. echo '</dd>';
  195. echo "\n";
  196. }
  197. echo '</dl></div></div>';
  198. echo '</div> <!-- end "#toolnav" -->';
  199. ?>
  200. <script type="text/javascript">
  201. /* <![CDATA[ */
  202. if(readCookie('dokeos_menu_state') == 0)
  203. {
  204. swap_menu();
  205. }
  206. /* ]]> */
  207. </script>
  208. <?php
  209. }
  210. }
  211. /**
  212. * Show a toolbar with shortcuts to the course tool
  213. */
  214. function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  215. {
  216. $navigation_items = get_navigation_items(false);
  217. foreach ($navigation_items as $key => $navigation_item)
  218. {
  219. echo '<a href="'.$navigation_item['link'].'"';
  220. if (strpos($_SERVER['PHP_SELF'], $navigation_item['link']) !== false)
  221. {
  222. echo ' id="here"';
  223. }
  224. echo ' target="_top" title="'.$navigation_item['name'].'">';
  225. echo '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  226. echo '</a>';
  227. if($orientation == SHORTCUTS_VERTICAL)
  228. {
  229. echo '<br />';
  230. }
  231. }
  232. }
  233. ?>