tool_navigation_menu.inc.php 8.2 KB

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