2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
17 5 sections: public, my_start_page, course, admin, home
19 if (isset($_pages[AT_NAV_ADMIN])) {
20 array_unshift($_pages[AT_NAV_ADMIN], 'admin/index.php', 'admin/modules/index.php');
23 $_pages[AT_NAV_PUBLIC] = array_merge(array('login.php', 'registration.php', 'browse.php'), (isset($_pages[AT_NAV_PUBLIC]) ? $_pages[AT_NAV_PUBLIC] : array()));
24 $_pages[AT_NAV_START] = array_merge(array('users/index.php', 'users/profile.php', 'users/preferences.php'), (array) $_pages[AT_NAV_START]);
25 $_pages[AT_NAV_COURSE] = array('index.php');
26 $_pages[AT_NAV_HOME] = array();
28 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) {
29 $main_links = $home_links = $side_menu = array();
31 if ($system_courses[$_SESSION['course_id']]['main_links']) {
32 $main_links = explode('|', $system_courses[$_SESSION['course_id']]['main_links']);
33 foreach ($main_links as $link) {
34 if (isset($_pages[$link])) {
35 $_pages[$link]['parent'] = AT_NAV_COURSE;
38 $_pages[AT_NAV_COURSE] = array_merge($_pages[AT_NAV_COURSE], $main_links);
41 if ($system_courses[$_SESSION['course_id']]['home_links']) {
42 $home_links = explode('|', $system_courses[$_SESSION['course_id']]['home_links']);
43 foreach ($home_links as $link) {
44 if (isset($_pages[$link])) {
45 $_pages[AT_NAV_HOME][] = $link;
50 if (authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)) {
51 $_pages[AT_NAV_COURSE][] = 'tools/index.php';
52 } else if ($_SESSION['privileges']) {
55 * the loop and all this module priv checking is done to hide the Manage tab
56 * when this student has privileges, but no items linked from the Manage tab.
57 * Example: the File Storage privilege does not have a Manage tab item.
58 * In the best case it stops after the first found link.
59 * In the worst case it goes through all the modules and doesn't find a link.
61 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);
62 $keys = array_keys($module_list);
64 foreach ($keys as $module_name) {
65 $module =& $module_list[$module_name];
66 if ($module->getPrivilege() && authenticate($module->getPrivilege(), AT_PRIV_RETURN) && ($module->getChildPage('tools/index.php'))) {
67 $_pages[AT_NAV_COURSE][] = 'tools/index.php';
72 } else if (isset($_SESSION['course_id']) && $_SESSION['course_id'] == -1) {
75 $_pages['admin/index.php']['title_var'] = 'home';
76 $_pages['admin/index.php']['parent'] = AT_NAV_ADMIN;
77 $_pages['admin/index.php']['guide'] = 'admin/?p=configuration.php';
78 $_pages['admin/index.php']['children'] = array_merge(array('admin/admins/my_edit.php', 'admin/admins/my_password.php'), isset($_pages['admin/index.php']['children']) ? $_pages['admin/index.php']['children'] : array());
80 $_pages['admin/admins/my_edit.php']['title_var'] = 'my_account';
81 $_pages['admin/admins/my_edit.php']['parent'] = 'admin/index.php';
82 $_pages['admin/admins/my_edit.php']['guide'] = 'admin/?p=my_account.php';
84 $_pages['admin/admins/my_password.php']['title_var'] = 'change_password';
85 $_pages['admin/admins/my_password.php']['parent'] = 'admin/index.php';
87 if (admin_authenticate(AT_ADMIN_PRIV_USERS, AT_PRIV_RETURN)) {
88 $_pages[AT_NAV_ADMIN][] = 'admin/config_edit.php';
90 $_pages['admin/config_edit.php']['title_var'] = 'system_preferences';
91 $_pages['admin/config_edit.php']['parent'] = AT_NAV_ADMIN;
92 $_pages['admin/config_edit.php']['guide'] = 'admin/?p=system_preferences.php';
93 $_pages['admin/config_edit.php']['children'] = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/error_logging.php'));
95 $_pages['admin/fix_content.php']['title_var'] = 'fix_content_ordering';
96 $_pages['admin/fix_content.php']['parent'] = 'admin/index.php';
98 $_pages['admin/error_logging.php']['title_var'] = 'error_logging';
99 $_pages['admin/error_logging.php']['parent'] = 'admin/config_edit.php';
100 $_pages['admin/error_logging.php']['guide'] = 'admin/?p=error_logging.php';
101 $_pages['admin/error_logging.php']['children'] = array_merge(array('admin/error_logging_bundle.php', 'admin/error_logging_reset.php'), isset($_pages['admin/error_logging.php']['children']) ? $_pages['admin/error_logging.php']['children'] : array());
103 $_pages['admin/error_logging_reset.php']['title_var'] = 'reset_log';
104 $_pages['admin/error_logging_reset.php']['parent'] = 'admin/error_logging.php';
106 $_pages['admin/error_logging_bundle.php']['title_var'] = 'report_errors';
107 $_pages['admin/error_logging_bundle.php']['parent'] = 'admin/error_logging.php';
109 $_pages['admin/error_logging_details.php']['title_var'] = 'viewing_profile_bugs';
110 $_pages['admin/error_logging_details.php']['parent'] = 'admin/error_logging.php';
112 $_pages['admin/error_logging_view.php']['title_var'] = 'viewing_errors';
113 $_pages['admin/error_logging_view.php']['parent'] = 'admin/error_logging_details.php';
115 if (admin_authenticate(AT_ADMIN_PRIV_ADMIN, TRUE)) {
116 // hide modules from non-super admins
117 $_pages['admin/modules/index.php']['title_var'] = 'modules';
118 $_pages['admin/modules/index.php']['parent'] = AT_NAV_ADMIN;
119 $_pages['admin/modules/index.php']['guide'] = 'admin/?p=modules.php';
120 $_pages['admin/modules/index.php']['children'] = array('admin/modules/add_new.php');
122 $_pages['admin/modules/details.php']['title_var'] = 'details';
123 $_pages['admin/modules/details.php']['parent'] = 'admin/modules/index.php';
125 $_pages['admin/modules/add_new.php']['title_var'] = 'install_modules';
126 $_pages['admin/modules/add_new.php']['parent'] = 'admin/modules/index.php';
128 $_pages['admin/modules/confirm.php']['title_var'] = 'confirm';
129 $_pages['admin/modules/confirm.php']['parent'] = 'admin/modules/add_new.php';
131 //$_pages['admin/modules/create.php']['title_var'] = 'create_module';
132 //$_pages['admin/modules/create.php']['parent'] = 'admin/modules/index.php';
134 $_pages['admin/cron_config.php']['title_var'] = 'cron_config';
135 $_pages['admin/cron_config.php']['parent'] = 'admin/config_edit.php';
136 $_pages['admin/cron_config.php']['guide'] = 'admin/?p=cron_setup.php';
137 $_pages['admin/config_edit.php']['children'] = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/cron_config.php'));
143 $_pages['registration.php']['title_var'] = 'register';
144 $_pages['registration.php']['parent'] = AT_NAV_PUBLIC;
145 $_pages['registration.php']['children'] = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
146 $_pages['registration.php']['guide'] = 'general/?p=register.php';
148 $_pages['browse.php']['title_var'] = 'browse_courses';
149 $_pages['browse.php']['parent'] = AT_NAV_PUBLIC;
150 $_pages['browse.php']['children'] = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
151 $_pages['browse.php']['guide'] = 'general/?p=browse_courses.php';
153 $_pages['login.php']['title_var'] = 'login';
154 $_pages['login.php']['parent'] = AT_NAV_PUBLIC;
155 $_pages['login.php']['children'] = array_merge(array('password_reminder.php'), isset($_pages['login.php']['children']) ? $_pages['login.php']['children'] : array());
156 $_pages['login.php']['guide'] = 'general/?p=login.php';
158 $_pages['confirm.php']['title_var'] = 'confirm';
159 $_pages['confirm.php']['parent'] = AT_NAV_PUBLIC;
161 $_pages['password_reminder.php']['title_var'] = 'password_reminder';
162 $_pages['password_reminder.php']['parent'] = 'login.php';
163 $_pages['password_reminder.php']['guide'] = 'general/?p=password_reminder.php';
165 $_pages['logout.php']['title_var'] = 'logout';
166 $_pages['logout.php']['parent'] = AT_NAV_PUBLIC;
168 /* my start page pages */
169 $_pages['users/index.php']['title_var'] = 'my_courses';
170 $_pages['users/index.php']['parent'] = AT_NAV_START;
171 $_pages['users/index.php']['guide'] = 'general/?p=my_courses.php';
172 if (isset($_SESSION['member_id']) && $_SESSION['member_id'] && (!isset($_SESSION['course_id']) || !$_SESSION['course_id'])) {
173 if ((get_instructor_status() === FALSE) && (!defined('ALLOW_INSTRUCTOR_REQUESTS') || !ALLOW_INSTRUCTOR_REQUESTS)) {
174 $_pages['users/index.php']['children'] = array_merge(array('users/browse.php'), (array) $_pages['users/index.php']['children']);
176 $_pages['users/index.php']['children'] = array_merge(array('users/browse.php', 'users/create_course.php'), isset($_pages['users/index.php']['children']) ? $_pages['users/index.php']['children'] : array());
180 $_pages['users/browse.php']['title_var'] = 'browse_courses';
181 $_pages['users/browse.php']['parent'] = 'users/index.php';
182 $_pages['users/browse.php']['guide'] = 'general/?p=browse_courses.php';
184 $_pages['users/create_course.php']['title_var'] = 'create_course';
185 $_pages['users/create_course.php']['parent'] = 'users/index.php';
186 $_pages['users/create_course.php']['guide'] = 'instructor/?p=creating_courses.php';
188 $_pages['users/private_enroll.php']['title_var'] = 'enroll';
189 $_pages['users/private_enroll.php']['parent'] = 'users/index.php';
191 $_pages['users/remove_course.php']['title_var'] = 'unenroll';
192 $_pages['users/remove_course.php']['parent'] = 'users/index.php';
194 $_pages['users/profile.php']['title_var'] = 'profile';
195 $_pages['users/profile.php']['parent'] = AT_NAV_START;
196 $_pages['users/profile.php']['guide'] = 'general/?p=profile.php';
197 $_pages['users/profile.php']['children'] = array_merge(array('users/password_change.php', 'users/email_change.php'), (array) $_pages['users/profile.php']['children']);
199 $_pages['users/password_change.php']['title_var'] = 'change_password';
200 $_pages['users/password_change.php']['parent'] = 'users/profile.php';
201 //$_pages['users/password_change.php']['guide'] = 'instructor/?p=creating_courses.php';
203 $_pages['users/email_change.php']['title_var'] = 'change_email';
204 $_pages['users/email_change.php']['parent'] = 'users/profile.php';
206 $_pages['users/preferences.php']['title_var'] = 'preferences';
207 $_pages['users/preferences.php']['parent'] = AT_NAV_START;
208 $_pages['users/preferences.php']['guide'] = 'general/?p=preferences.php';
212 $_pages['index.php']['title_var'] = 'home';
213 $_pages['index.php']['parent'] = AT_NAV_COURSE;
215 $_pages['enroll.php']['title_var'] = 'enroll';
216 $_pages['enroll.php']['parent'] = AT_NAV_COURSE;
218 /* instructor pages: */
219 $_pages['tools/index.php']['title_var'] = 'manage';
220 $_pages['tools/index.php']['parent'] = AT_NAV_COURSE;
222 $_pages['inbox/index.php']['title_var'] = 'inbox';
223 $_pages['inbox/index.php']['children'] = array_merge(array('inbox/sent_messages.php', 'inbox/send_message.php', 'inbox/export.php'), isset($_pages['inbox/index.php']['children']) ? $_pages['inbox/index.php']['children'] : array());
225 $_pages['inbox/sent_messages.php']['title_var'] = 'sent_messages';
226 $_pages['inbox/sent_messages.php']['parent'] = 'inbox/index.php';
228 $_pages['inbox/send_message.php']['title_var'] = 'send_message';
229 $_pages['inbox/send_message.php']['parent'] = 'inbox/index.php';
231 $_pages['inbox/export.php']['title_var'] = 'export';
232 $_pages['inbox/export.php']['parent'] = 'inbox/index.php';
234 $_pages['profile.php']['title_var'] = 'profile';
235 $_pages['profile.php']['parent'] = 'index.php';
239 $_pages['about.php']['title_var'] = 'about_atutor';
241 $_pages['404.php']['title_var'] = '404';
243 $_pages['help/index.php']['title_var'] = 'help';
244 $_pages['help/index.php']['children'] = array_merge(array('help/accessibility.php', 'help/contact_support.php'), isset($_pages['help/index.php']['children']) ? $_pages['help/index.php']['children'] : array());
246 $_pages['help/accessibility.php']['title_var'] = 'accessibility';
247 $_pages['help/accessibility.php']['parent'] = 'help/index.php';
249 $_pages['help/contact_support.php']['title_var'] = 'contact_support';
250 $_pages['help/contact_support.php']['parent'] = 'help/index.php';
253 $_pages['contact_instructor.php']['title_var'] = 'contact_instructor';
255 $current_page = substr($_SERVER['PHP_SELF'], strlen($_base_path));
257 function get_num_new_messages() {
259 static $num_messages;
261 if (isset($num_messages)) {
262 return $num_messages;
264 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND new=1";
265 $result = mysql_query($sql, $db);
266 $row = mysql_fetch_assoc($result);
267 $num_messages = $row['cnt'];
269 return $num_messages;
272 function get_main_navigation($current_page) {
273 global $_pages, $_base_path;
275 $parent_page = $_pages[$current_page]['parent'];
276 $_top_level_pages = array();
278 if (isset($parent_page) && defined($parent_page)) {
279 foreach($_pages[$parent_page] as $page) {
280 if (isset($_pages[$page])) {
281 if (isset($_pages[$page]['title'])) {
282 $_page_title = $_pages[$page]['title'];
284 $_page_title = _AT($_pages[$page]['title_var']);
287 $_top_level_pages[] = array('url' => $_base_path . $page, 'title' => $_page_title);
290 } else if (isset($parent_page)) {
291 return get_main_navigation($parent_page);
294 return $_top_level_pages;
297 function get_current_main_page($current_page) {
298 global $_pages, $_base_path;
300 $parent_page = $_pages[$current_page]['parent'];
302 if (isset($parent_page) && defined($parent_page)) {
303 return $_base_path . $current_page;
304 } else if (isset($parent_page)) {
305 return get_current_main_page($parent_page);
309 function get_sub_navigation($current_page) {
310 global $_pages, $_base_path;
312 if (isset($current_page) && defined($current_page)) {
315 } else if (isset($_pages[$current_page]['children'])) {
316 if (isset($_pages[$current_page]['title'])) {
317 $_page_title = $_pages[$current_page]['title'];
319 $_page_title = _AT($_pages[$current_page]['title_var']);
322 $_sub_level_pages[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
323 foreach ($_pages[$current_page]['children'] as $child) {
325 if (isset($_pages[$child]['title'])) {
326 $_page_title = $_pages[$child]['title'];
328 $_page_title = _AT($_pages[$child]['title_var']);
331 $_sub_level_pages[] = array('url' => $_base_path . $child, 'title' => $_page_title, 'has_children' => isset($_pages[$child]['children']));
333 } else if (isset($_pages[$current_page]['parent'])) {
336 $parent_page = $_pages[$current_page]['parent'];
337 return get_sub_navigation($parent_page);
340 return $_sub_level_pages;
343 function get_current_sub_navigation_page($current_page) {
344 global $_pages, $_base_path;
346 $parent_page = $_pages[$current_page]['parent'];
348 if (isset($parent_page) && defined($parent_page)) {
349 return $_base_path . $current_page;
351 return $_base_path . $current_page;
355 function get_path($current_page) {
356 global $_pages, $_base_path;
358 $parent_page = $_pages[$current_page]['parent'];
360 if (isset($_pages[$current_page]['title'])) {
361 $_page_title = $_pages[$current_page]['title'];
363 $_page_title = _AT($_pages[$current_page]['title_var']);
366 if (isset($parent_page) && defined($parent_page)) {
367 $path[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
369 } else if (isset($parent_page)) {
370 $path[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
371 $path = array_merge((array) $path, get_path($parent_page));
373 $path[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
379 function get_home_navigation() {
380 global $_pages, $_base_path;
382 $home_links = array();
383 foreach ($_pages[AT_NAV_HOME] as $child) {
384 if (isset($_pages[$child])) {
385 if (isset($_pages[$child]['title'])) {
386 $title = $_pages[$child]['title'];
388 $title = _AT($_pages[$child]['title_var']);
390 $home_links[] = array('url' => $_base_path . $child, 'title' => $title, 'img' => $_base_path.$_pages[$child]['img']);