tool_navigation_menu.inc.php 8.2 KB

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