Tag for ATutor 1.6.
[atutor.git] / include / lib / menu_pages.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
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 /************************************************************************/
13 // $Id$
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15
16 /*
17         5 sections: public, my_start_page, course, admin, home
18 */
19 if (isset($_pages[AT_NAV_ADMIN])) {
20         array_unshift($_pages[AT_NAV_ADMIN], 'admin/index.php', 'admin/modules/index.php');
21 }
22
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();
27
28 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) {
29         $main_links = $home_links = $side_menu = array();
30
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;
36                         }
37                 }
38                 $_pages[AT_NAV_COURSE] = array_merge($_pages[AT_NAV_COURSE], $main_links);
39         }
40
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;
46                         }
47                 }
48         }
49
50         if (authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)) {
51                 $_pages[AT_NAV_COURSE][] = 'tools/index.php';           
52         } else if ($_SESSION['privileges']) {
53                 
54                 /**
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.
60                  */
61                 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);
62                 $keys = array_keys($module_list);
63
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';
68                                 break;
69                         }
70                 }
71         }
72 } else if (isset($_SESSION['course_id']) && $_SESSION['course_id'] == -1) {
73         /* admin pages */
74
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());
79
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';
83
84         $_pages['admin/admins/my_password.php']['title_var'] = 'change_password';
85         $_pages['admin/admins/my_password.php']['parent']    = 'admin/index.php';
86
87         if (admin_authenticate(AT_ADMIN_PRIV_USERS, AT_PRIV_RETURN)) {
88                 $_pages[AT_NAV_ADMIN][] = 'admin/config_edit.php';
89
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'));
94         }
95         $_pages['admin/fix_content.php']['title_var'] = 'fix_content_ordering';
96         $_pages['admin/fix_content.php']['parent']    = 'admin/index.php';
97
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());
102
103         $_pages['admin/error_logging_reset.php']['title_var'] = 'reset_log';
104         $_pages['admin/error_logging_reset.php']['parent']    = 'admin/error_logging.php';
105
106         $_pages['admin/error_logging_bundle.php']['title_var'] = 'report_errors';
107         $_pages['admin/error_logging_bundle.php']['parent']    = 'admin/error_logging.php';
108
109         $_pages['admin/error_logging_details.php']['title_var'] = 'viewing_profile_bugs';
110         $_pages['admin/error_logging_details.php']['parent']    = 'admin/error_logging.php';
111
112         $_pages['admin/error_logging_view.php']['title_var'] = 'viewing_errors';
113         $_pages['admin/error_logging_view.php']['parent']    = 'admin/error_logging_details.php';
114
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');
121
122                 $_pages['admin/modules/details.php']['title_var'] = 'details';
123                 $_pages['admin/modules/details.php']['parent']    = 'admin/modules/index.php';
124
125                 $_pages['admin/modules/add_new.php']['title_var'] = 'install_modules';
126                 $_pages['admin/modules/add_new.php']['parent']    = 'admin/modules/index.php';
127
128                         $_pages['admin/modules/confirm.php']['title_var'] = 'confirm';
129                         $_pages['admin/modules/confirm.php']['parent']    = 'admin/modules/add_new.php';
130
131                 //$_pages['admin/modules/create.php']['title_var'] = 'create_module';
132                 //$_pages['admin/modules/create.php']['parent']    = 'admin/modules/index.php';
133
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'));
138         }
139 }
140
141
142 /* public pages */
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';
147
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';
152
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';
157
158 $_pages['confirm.php']['title_var'] = 'confirm';
159 $_pages['confirm.php']['parent']    = AT_NAV_PUBLIC;
160
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';
164
165 $_pages['logout.php']['title_var'] = 'logout';
166 $_pages['logout.php']['parent']    = AT_NAV_PUBLIC;
167
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']);
175         } else {
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());
177         }
178 }
179         
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';
183         
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';
187
188         $_pages['users/private_enroll.php']['title_var'] = 'enroll';
189         $_pages['users/private_enroll.php']['parent']    = 'users/index.php';
190
191         $_pages['users/remove_course.php']['title_var'] = 'unenroll';
192         $_pages['users/remove_course.php']['parent']    = 'users/index.php';
193
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']);
198
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';
202
203         $_pages['users/email_change.php']['title_var'] = 'change_email';
204         $_pages['users/email_change.php']['parent']    = 'users/profile.php';
205
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';
209
210
211 /* course pages */
212 $_pages['index.php']['title_var']  = 'home';
213 $_pages['index.php']['parent'] = AT_NAV_COURSE;
214
215 $_pages['enroll.php']['title_var']  = 'enroll';
216 $_pages['enroll.php']['parent'] = AT_NAV_COURSE;
217
218 /* instructor pages: */
219 $_pages['tools/index.php']['title_var'] = 'manage';
220 $_pages['tools/index.php']['parent']    = AT_NAV_COURSE;
221
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());
224
225         $_pages['inbox/sent_messages.php']['title_var'] = 'sent_messages';
226         $_pages['inbox/sent_messages.php']['parent']    = 'inbox/index.php';
227
228         $_pages['inbox/send_message.php']['title_var'] = 'send_message';
229         $_pages['inbox/send_message.php']['parent']    = 'inbox/index.php';
230
231         $_pages['inbox/export.php']['title_var'] = 'export';
232         $_pages['inbox/export.php']['parent']    = 'inbox/index.php';
233
234 $_pages['profile.php']['title_var'] = 'profile';
235 $_pages['profile.php']['parent']    = 'index.php';
236
237
238 /* global pages */
239 $_pages['about.php']['title_var']  = 'about_atutor';
240
241 $_pages['404.php']['title_var']  = '404';
242
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());
245
246         $_pages['help/accessibility.php']['title_var']  = 'accessibility';
247         $_pages['help/accessibility.php']['parent'] = 'help/index.php';
248
249         $_pages['help/contact_support.php']['title_var']  = 'contact_support';
250         $_pages['help/contact_support.php']['parent'] = 'help/index.php';
251
252
253 $_pages['contact_instructor.php']['title_var']  = 'contact_instructor';
254
255 $current_page = substr($_SERVER['PHP_SELF'], strlen($_base_path));
256
257 function get_num_new_messages() {
258         global $db;
259         static $num_messages;
260
261         if (isset($num_messages)) {
262                 return $num_messages;
263         }
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'];
268
269         return $num_messages;
270 }
271
272 function get_main_navigation($current_page) {
273         global $_pages, $_base_path;
274
275         $parent_page = $_pages[$current_page]['parent'];
276         $_top_level_pages = array();
277
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'];
283                                 } else {
284                                         $_page_title = _AT($_pages[$page]['title_var']);
285                                 }
286                                 
287                                 $_top_level_pages[] = array('url' => $_base_path . $page, 'title' => $_page_title);
288                         }
289                 }
290         } else if (isset($parent_page)) {
291                 return get_main_navigation($parent_page);
292         }
293
294         return $_top_level_pages;
295 }
296
297 function get_current_main_page($current_page) {
298         global $_pages, $_base_path;
299
300         $parent_page = $_pages[$current_page]['parent'];
301
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);
306         }
307 }
308
309 function get_sub_navigation($current_page) {
310         global $_pages, $_base_path;
311
312         if (isset($current_page) && defined($current_page)) {
313                 // reached the top
314                 return array();
315         } else if (isset($_pages[$current_page]['children'])) {
316                 if (isset($_pages[$current_page]['title'])) {
317                         $_page_title = $_pages[$current_page]['title'];
318                 } else {
319                         $_page_title = _AT($_pages[$current_page]['title_var']);
320                 }
321
322                 $_sub_level_pages[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
323                 foreach ($_pages[$current_page]['children'] as $child) {
324
325                         if (isset($_pages[$child]['title'])) {
326                                 $_page_title = $_pages[$child]['title'];
327                         } else {
328                                 $_page_title = _AT($_pages[$child]['title_var']);
329                         }
330
331                         $_sub_level_pages[] = array('url' => $_base_path . $child, 'title' => $_page_title, 'has_children' => isset($_pages[$child]['children']));
332                 }
333         } else if (isset($_pages[$current_page]['parent'])) {
334                 // no children
335
336                 $parent_page = $_pages[$current_page]['parent'];
337                 return get_sub_navigation($parent_page);
338         }
339
340         return $_sub_level_pages;
341 }
342
343 function get_current_sub_navigation_page($current_page) {
344         global $_pages, $_base_path;
345
346         $parent_page = $_pages[$current_page]['parent'];
347
348         if (isset($parent_page) && defined($parent_page)) {
349                 return $_base_path . $current_page;
350         } else {
351                 return $_base_path . $current_page;
352         }
353 }
354
355 function get_path($current_page) {
356         global $_pages, $_base_path;
357
358         $parent_page = $_pages[$current_page]['parent'];
359
360         if (isset($_pages[$current_page]['title'])) {
361                 $_page_title = $_pages[$current_page]['title'];
362         } else {
363                 $_page_title = _AT($_pages[$current_page]['title_var']);
364         }
365
366         if (isset($parent_page) && defined($parent_page)) {
367                 $path[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
368                 return $path;
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));
372         } else {
373                 $path[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
374         }
375         
376         return $path;
377 }
378
379 function get_home_navigation() {
380         global $_pages, $_base_path;
381
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'];
387                         } else {
388                                 $title = _AT($_pages[$child]['title_var']);
389                         }
390                         $home_links[] = array('url' => $_base_path . $child, 'title' => $title, 'img' => $_base_path.$_pages[$child]['img']);
391                 }
392         }
393
394         return $home_links;
395 }
396 ?>