tool_navigation_menu.inc.php 8.3 KB

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