tool_navigation_menu.inc.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. // $Id: tool_navigation_menu.inc.php 22072 2009-07-14 15:14:42Z jhp1411 $
  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. global $_user;
  39. global $_course;
  40. if (!empty($_course['db_name']))
  41. {
  42. $database = $_course['db_name'];
  43. }
  44. $navigation_items = array ();
  45. $course_id = api_get_course_id();
  46. if (!empty ($course_id) && ($course_id != -1))
  47. {
  48. $user_id = api_get_user_id();
  49. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST,$database);
  50. /*
  51. --------------------------------------------------------------
  52. Link to the Course homepage
  53. --------------------------------------------------------------
  54. */
  55. $navigation_items['home']['image'] = 'home.gif';
  56. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).$_SESSION['_course']['path'].'/index.php';
  57. $navigation_items['home']['name'] = get_lang("CourseHomepageLink");
  58. /*
  59. --------------------------------------------------------------
  60. Link to the different tools
  61. --------------------------------------------------------------
  62. */
  63. $sql_menu_query = "SELECT * FROM $course_tools_table WHERE visibility='1' and admin='0' ORDER BY id ASC";
  64. $sql_result = api_sql_query($sql_menu_query, __FILE__, __LINE__);
  65. while ($row = mysql_fetch_array($sql_result))
  66. {
  67. $navigation_items[$row['id']] = $row;
  68. /*
  69. if (!stristr($row['link'], 'http://'))
  70. */
  71. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false)
  72. {
  73. $navigation_items[$row['id']]['link'] = api_get_path(REL_CODE_PATH).$row['link'];
  74. /*
  75. $navigation_items[$row['id']]['name'] = $row['image'] == 'scormbuilder.gif' ? $navigation_items[$row['id']]['name'] : get_lang(ucfirst($navigation_items[$row['id']]['name']));
  76. */
  77. if ($row['image'] != 'scormbuilder.gif' && $row['image'] != 'blog.gif')
  78. {
  79. $navigation_items[$row['id']]['name'] = get_lang(ucfirst($navigation_items[$row['id']]['name']));
  80. }
  81. }
  82. }
  83. /*
  84. --------------------------------------------------------------
  85. Admin (edit rights) only links
  86. - Course settings (course admin only)
  87. - Course rights (roles & rights overview)
  88. --------------------------------------------------------------
  89. */
  90. if ($include_admin_tools)
  91. {
  92. $course_settings_sql = " SELECT name,image FROM $course_tools_table
  93. WHERE link='course_info/infocours.php'";
  94. $sql_result = api_sql_query($course_settings_sql);
  95. $course_setting_info = mysql_fetch_array($sql_result);
  96. $course_setting_visual_name = get_lang(ucfirst($course_setting_info['name']));
  97. if (api_get_session_id()==0) {
  98. // course settings item
  99. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  100. $navigation_items['course_settings']['link'] = api_get_path(REL_CODE_PATH).'course_info/infocours.php';
  101. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  102. }
  103. }
  104. }
  105. foreach($navigation_items as $key => $navigation_item)
  106. {
  107. if (strstr($navigation_item['link'], '?'))
  108. {
  109. //link already contains a parameter, add course id parameter with &
  110. $parameter_separator = '&amp;';
  111. }
  112. else
  113. {
  114. //link doesn't contain a parameter yet, add course id parameter with ?
  115. $parameter_separator = '?';
  116. }
  117. $navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  118. }
  119. return $navigation_items;
  120. }
  121. /**
  122. * Show a navigation menu
  123. */
  124. function show_navigation_menu()
  125. {
  126. $navigation_items = get_navigation_items(true);
  127. $course_id = api_get_course_id();
  128. if(api_get_setting('show_navigation_menu') == 'icons')
  129. {
  130. echo '<div style="float:right;width: 40px;position:absolute;right:10px;top:10px;">';
  131. show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  132. echo '</div>';
  133. }
  134. else
  135. {
  136. echo '<div id="toolnav"> <!-- start of #toolnav -->';
  137. ?>
  138. <script type="text/javascript">
  139. /* <![CDATA[ */
  140. function createCookie(name,value,days)
  141. {
  142. if (days)
  143. {
  144. var date = new Date();
  145. date.setTime(date.getTime()+(days*24*60*60*1000));
  146. var expires = "; expires="+date.toGMTString();
  147. }
  148. else var expires = "";
  149. document.cookie = name+"="+value+expires+"; path=/";
  150. }
  151. function readCookie(name)
  152. {
  153. var nameEQ = name + "=";
  154. var ca = document.cookie.split(';');
  155. for(var i=0;i < ca.length;i++)
  156. {
  157. var c = ca[i];
  158. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  159. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  160. }
  161. return null;
  162. }
  163. function swap_menu()
  164. {
  165. toolnavlist_el = document.getElementById('toolnavlist');
  166. center_el = document.getElementById('center');
  167. swap_menu_link_el = document.getElementById('swap_menu_link');
  168. if(toolnavlist_el.style.display == 'none')
  169. {
  170. toolnavlist_el.style.display = '';
  171. if (center_el)
  172. {
  173. center_el.style.margin = '0 190px 0 0';
  174. }
  175. swap_menu_link_el.innerHTML = '<?php echo get_lang('Hide'); ?> &raquo;&raquo;';
  176. createCookie('dokeos_menu_state',1,10);
  177. }
  178. else
  179. {
  180. toolnavlist_el.style.display = 'none';
  181. if (center_el)
  182. {
  183. center_el.style.margin = '0 0 0 0';
  184. }
  185. swap_menu_link_el.innerHTML = '&laquo;&laquo; <?php echo get_lang('Show'); ?>';
  186. createCookie('dokeos_menu_state',0,10);
  187. }
  188. }
  189. document.write('<a href="javascript: void(0);" id="swap_menu_link" onclick="javascript: swap_menu();"><?php echo get_lang('Hide'); ?> &raquo;&raquo;<\/a>');
  190. /* ]]> */
  191. </script>
  192. <?php
  193. echo '<div id="toolnavbox">';
  194. echo '<div id="toolnavlist"><dl>';
  195. foreach ($navigation_items as $key => $navigation_item)
  196. {
  197. echo '<dd>';
  198. $url_item = parse_url($navigation_item['link']);
  199. $url_current = parse_url($_SERVER['REQUEST_URI']);
  200. if (strpos($navigation_item['link'],'chat')!==false && api_get_course_setting('allow_open_chat_window',$course_id)==true)
  201. {
  202. echo '<a href="javascript: void(0);" onclick="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'] . '"';
  203. }
  204. else
  205. {
  206. echo '<a href="'.$navigation_item['link'].'" target="_self" ';
  207. }
  208. if (stristr($url_item['path'],$url_current['path']))
  209. {
  210. if(! isset($_GET['learnpath_id']) || strpos($url_item['query'],'learnpath_id='.$_GET['learnpath_id']) === 0)
  211. {
  212. echo ' id="here"';
  213. }
  214. }
  215. echo ' title="'.$navigation_item['name'].'">';
  216. if (api_get_setting('show_navigation_menu') != 'text')
  217. {
  218. echo '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  219. }
  220. if (api_get_setting('show_navigation_menu') != 'icons')
  221. {
  222. echo $navigation_item['name'];
  223. }
  224. echo '</a>';
  225. echo '</dd>';
  226. echo "\n";
  227. }
  228. echo '</dl></div></div>';
  229. echo '</div> <!-- end "#toolnav" -->';
  230. ?>
  231. <script type="text/javascript">
  232. /* <![CDATA[ */
  233. if(readCookie('dokeos_menu_state') == 0)
  234. {
  235. swap_menu();
  236. }
  237. /* ]]> */
  238. </script>
  239. <?php
  240. }
  241. }
  242. /**
  243. * Show a toolbar with shortcuts to the course tool
  244. */
  245. function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  246. {
  247. $navigation_items = get_navigation_items(false);
  248. foreach ($navigation_items as $key => $navigation_item)
  249. {
  250. if (strpos($navigation_item['link'],'chat')!==false && api_get_course_setting('allow_open_chat_window')==true)
  251. {
  252. /*
  253. echo '<a href="#" onclick="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'] . '"';
  254. */
  255. 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'] . '"';
  256. }
  257. else
  258. {
  259. echo '<a href="'.$navigation_item['link'].'"';
  260. }
  261. if (strpos(api_get_self(), $navigation_item['link']) !== false)
  262. {
  263. echo ' id="here"';
  264. }
  265. echo ' target="_self" title="'.$navigation_item['name'].'">';
  266. echo '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  267. echo '</a>';
  268. if($orientation == SHORTCUTS_VERTICAL)
  269. {
  270. echo '<br />';
  271. }
  272. }
  273. }
  274. ?>