tool_navigation_menu.inc.php 9.0 KB

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