a31bd0024e09f0be9207f648d0ca81848650d652
[atutor.git] / mods / ldap / 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: menu_pages.php 7575 2008-05-27 18:17:14Z hwong $
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         
99         /*
100         smal
101         09-09-2008
102         Add LDAP Auth pages for admin
103         */
104         
105         $_pages['admin/config_ldap.php']['title_var'] = 'config_ldap';
106         $_pages['admin/config_ldap.php']['parent']    = 'admin/config_edit.php';
107         $_pages['admin/config_edit.php']['children']  = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/config_ldap.php'));
108         
109         $_pages['admin/ldap_auth_log.php']['title_var'] = 'ldap_auth_log';
110         $_pages['admin/ldap_auth_log.php']['parent']    = 'admin/config_ldap.php';
111         $_pages['admin/config_ldap.php']['children']  = array_merge((array) $_pages['admin/config_ldap.php']['children'], array('admin/ldap_auth_log.php'));
112         
113         $_pages['admin/error_logging.php']['title_var'] = 'error_logging';
114         $_pages['admin/error_logging.php']['parent']    = 'admin/config_edit.php';
115         $_pages['admin/error_logging.php']['guide']     = 'admin/?p=error_logging.php';
116         $_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());
117
118         $_pages['admin/error_logging_reset.php']['title_var'] = 'reset_log';
119         $_pages['admin/error_logging_reset.php']['parent']    = 'admin/error_logging.php';
120
121         $_pages['admin/error_logging_bundle.php']['title_var'] = 'report_errors';
122         $_pages['admin/error_logging_bundle.php']['parent']    = 'admin/error_logging.php';
123
124         $_pages['admin/error_logging_details.php']['title_var'] = 'viewing_profile_bugs';
125         $_pages['admin/error_logging_details.php']['parent']    = 'admin/error_logging.php';
126
127         $_pages['admin/error_logging_view.php']['title_var'] = 'viewing_errors';
128         $_pages['admin/error_logging_view.php']['parent']    = 'admin/error_logging_details.php';
129
130         if (admin_authenticate(AT_ADMIN_PRIV_ADMIN, TRUE)) {
131                 // hide modules from non-super admins
132                 $_pages['admin/modules/index.php']['title_var'] = 'modules';
133                 $_pages['admin/modules/index.php']['parent']    = AT_NAV_ADMIN;
134                 $_pages['admin/modules/index.php']['guide']     = 'admin/?p=modules.php';
135                 $_pages['admin/modules/index.php']['children']  = array('admin/modules/add_new.php');
136
137                 $_pages['admin/modules/details.php']['title_var'] = 'details';
138                 $_pages['admin/modules/details.php']['parent']    = 'admin/modules/index.php';
139
140                 $_pages['admin/modules/add_new.php']['title_var'] = 'install_modules';
141                 $_pages['admin/modules/add_new.php']['parent']    = 'admin/modules/index.php';
142
143                         $_pages['admin/modules/confirm.php']['title_var'] = 'confirm';
144                         $_pages['admin/modules/confirm.php']['parent']    = 'admin/modules/add_new.php';
145
146                 //$_pages['admin/modules/create.php']['title_var'] = 'create_module';
147                 //$_pages['admin/modules/create.php']['parent']    = 'admin/modules/index.php';
148
149                 $_pages['admin/cron_config.php']['title_var'] = 'cron_config';
150                 $_pages['admin/cron_config.php']['parent']    = 'admin/config_edit.php';
151                 $_pages['admin/cron_config.php']['guide']     = 'admin/?p=cron_setup.php';
152                 $_pages['admin/config_edit.php']['children']  = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/cron_config.php'));
153
154                 $_pages['admin/auto_enroll.php']['title_var'] = 'auto_enroll';
155                 $_pages['admin/auto_enroll.php']['parent']    = 'admin/config_edit.php';
156                 $_pages['admin/auto_enroll.php']['guide']     = 'admin/?p=auto_enroll.php';
157                 $_pages['admin/auto_enroll.php']['children']  = array_merge(array('admin/auto_enroll_edit.php'));
158                 $_pages['admin/config_edit.php']['children']  = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/auto_enroll.php'));
159
160                 $_pages['admin/auto_enroll_edit.php']['title_var'] = 'auto_enroll_edit';
161                 $_pages['admin/auto_enroll_edit.php']['parent']    = 'admin/auto_enroll.php';
162         
163                 $_pages['admin/auto_enroll_delete.php']['title_var'] = 'auto_enroll_delete';
164                 $_pages['admin/auto_enroll_delete.php']['parent']    = 'admin/auto_enroll.php';
165         
166         }
167 }
168
169
170 /* public pages */
171 $_pages['registration.php']['title_var'] = 'register';
172 $_pages['registration.php']['parent']    = AT_NAV_PUBLIC;
173 $_pages['registration.php']['children']  = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
174 $_pages['registration.php']['guide']     = 'general/?p=register.php';
175
176 $_pages['browse.php']['title_var'] = 'browse_courses';
177 $_pages['browse.php']['parent']    = AT_NAV_PUBLIC;
178 $_pages['browse.php']['children']  = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
179 $_pages['browse.php']['guide']     = 'general/?p=browse_courses.php';
180
181 $_pages['login.php']['title_var'] = 'login';
182 $_pages['login.php']['parent']    = AT_NAV_PUBLIC;
183 $_pages['login.php']['children']  = array_merge(array('password_reminder.php'), isset($_pages['login.php']['children']) ? $_pages['login.php']['children'] : array());
184 $_pages['login.php']['guide']     = 'general/?p=login.php';
185
186 $_pages['confirm.php']['title_var'] = 'confirm';
187 $_pages['confirm.php']['parent']    = AT_NAV_PUBLIC;
188
189 $_pages['password_reminder.php']['title_var'] = 'password_reminder';
190 $_pages['password_reminder.php']['parent']    = 'login.php';
191 $_pages['password_reminder.php']['guide']     = 'general/?p=password_reminder.php';
192
193 $_pages['logout.php']['title_var'] = 'logout';
194 $_pages['logout.php']['parent']    = AT_NAV_PUBLIC;
195
196 /* my start page pages */
197 $_pages['users/index.php']['title_var'] = 'my_courses';
198 $_pages['users/index.php']['parent']    = AT_NAV_START;
199 $_pages['users/index.php']['guide']     = 'general/?p=my_courses.php';
200 if (isset($_SESSION['member_id']) && $_SESSION['member_id'] && (!isset($_SESSION['course_id']) || !$_SESSION['course_id'])) {
201         if ((get_instructor_status() === FALSE) && (!defined('ALLOW_INSTRUCTOR_REQUESTS') || !ALLOW_INSTRUCTOR_REQUESTS)) {
202                 $_pages['users/index.php']['children']  = array_merge(array('users/browse.php'), (array) $_pages['users/index.php']['children']);
203         } else {
204                 $_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());
205         }
206 }
207         
208         $_pages['users/browse.php']['title_var'] = 'browse_courses';
209         $_pages['users/browse.php']['parent']    = 'users/index.php';
210         $_pages['users/browse.php']['guide']     = 'general/?p=browse_courses.php';
211         
212         $_pages['users/create_course.php']['title_var'] = 'create_course';
213         $_pages['users/create_course.php']['parent']    = 'users/index.php';
214         $_pages['users/create_course.php']['guide']    = 'instructor/?p=creating_courses.php';
215
216         $_pages['users/private_enroll.php']['title_var'] = 'enroll';
217         $_pages['users/private_enroll.php']['parent']    = 'users/index.php';
218
219         $_pages['users/remove_course.php']['title_var'] = 'unenroll';
220         $_pages['users/remove_course.php']['parent']    = 'users/index.php';
221
222 $_pages['users/profile.php']['title_var']    = 'profile';
223 $_pages['users/profile.php']['parent']   = AT_NAV_START;
224 $_pages['users/profile.php']['guide']     = 'general/?p=profile.php';
225 $_pages['users/profile.php']['children']  = array_merge(array('users/password_change.php', 'users/email_change.php'), (array) $_pages['users/profile.php']['children']);
226
227         $_pages['users/password_change.php']['title_var'] = 'change_password';
228         $_pages['users/password_change.php']['parent']    = 'users/profile.php';
229         //$_pages['users/password_change.php']['guide']    = 'instructor/?p=creating_courses.php';
230
231         $_pages['users/email_change.php']['title_var'] = 'change_email';
232         $_pages['users/email_change.php']['parent']    = 'users/profile.php';
233
234 $_pages['users/preferences.php']['title_var']  = 'preferences';
235 $_pages['users/preferences.php']['parent'] = AT_NAV_START;
236 $_pages['users/preferences.php']['guide']  = 'general/?p=preferences.php';
237
238
239 /* course pages */
240 $_pages['index.php']['title_var']  = 'home';
241 $_pages['index.php']['parent'] = AT_NAV_COURSE;
242
243 $_pages['enroll.php']['title_var']  = 'enroll';
244 $_pages['enroll.php']['parent'] = AT_NAV_COURSE;
245
246 /* instructor pages: */
247 $_pages['tools/index.php']['title_var'] = 'manage';
248 $_pages['tools/index.php']['parent']    = AT_NAV_COURSE;
249
250 $_pages['inbox/index.php']['title_var'] = 'inbox';
251 $_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());
252
253         $_pages['inbox/sent_messages.php']['title_var'] = 'sent_messages';
254         $_pages['inbox/sent_messages.php']['parent']    = 'inbox/index.php';
255
256         $_pages['inbox/send_message.php']['title_var'] = 'send_message';
257         $_pages['inbox/send_message.php']['parent']    = 'inbox/index.php';
258
259         $_pages['inbox/export.php']['title_var'] = 'export';
260         $_pages['inbox/export.php']['parent']    = 'inbox/index.php';
261
262 $_pages['profile.php']['title_var'] = 'profile';
263 $_pages['profile.php']['parent']    = 'index.php';
264
265
266 /* global pages */
267 $_pages['about.php']['title_var']  = 'about_atutor';
268
269 $_pages['404.php']['title_var']  = '404';
270
271 $_pages['help/index.php']['title_var']  = 'help';
272 $_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());
273
274         $_pages['help/accessibility.php']['title_var']  = 'accessibility';
275         $_pages['help/accessibility.php']['parent'] = 'help/index.php';
276
277         $_pages['help/contact_support.php']['title_var']  = 'contact_support';
278         $_pages['help/contact_support.php']['parent'] = 'help/index.php';
279
280
281 $_pages['contact_instructor.php']['title_var']  = 'contact_instructor';
282
283 $current_page = substr($_SERVER['PHP_SELF'], strlen($_base_path));
284
285 function get_num_new_messages() {
286         global $db;
287         static $num_messages;
288
289         if (isset($num_messages)) {
290                 return $num_messages;
291         }
292         $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND new=1";
293         $result = mysql_query($sql, $db);
294         $row    = mysql_fetch_assoc($result);
295         $num_messages = $row['cnt'];
296
297         return $num_messages;
298 }
299
300 function get_main_navigation($current_page) {
301         global $_pages, $_base_path;
302
303         $parent_page = $_pages[$current_page]['parent'];
304         $_top_level_pages = array();
305
306         if (isset($parent_page) && defined($parent_page)) {
307                 foreach($_pages[$parent_page] as $page) {
308                         if (isset($_pages[$page])) {
309                                 if (isset($_pages[$page]['title'])) {
310                                         $_page_title = $_pages[$page]['title'];
311                                 } else {
312                                         $_page_title = _AT($_pages[$page]['title_var']);
313                                 }
314                                 
315                                 $_top_level_pages[] = array('url' => $_base_path . url_rewrite($page), 'title' => $_page_title);
316                         }
317                 }
318         } else if (isset($parent_page)) {
319                 return get_main_navigation($parent_page);
320         }
321
322         return $_top_level_pages;
323 }
324
325 function get_current_main_page($current_page) {
326         global $_pages, $_base_path;
327
328         $parent_page = $_pages[$current_page]['parent'];
329
330         if (isset($parent_page) && defined($parent_page)) {
331                 return $_base_path . url_rewrite($current_page);
332         } else if (isset($parent_page)) {
333                 return get_current_main_page($parent_page);
334         }
335 }
336
337 function get_sub_navigation($current_page) {
338         global $_pages, $_base_path;
339
340         if (isset($current_page) && defined($current_page)) {
341                 // reached the top
342                 return array();
343         } else if (isset($_pages[$current_page]['children'])) {
344                 if (isset($_pages[$current_page]['title'])) {
345                         $_page_title = $_pages[$current_page]['title'];
346                 } else {
347                         $_page_title = _AT($_pages[$current_page]['title_var']);
348                 }
349
350                 $_sub_level_pages[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
351                 foreach ($_pages[$current_page]['children'] as $child) {
352
353                         if (isset($_pages[$child]['title'])) {
354                                 $_page_title = $_pages[$child]['title'];
355                         } else {
356                                 $_page_title = _AT($_pages[$child]['title_var']);
357                         }
358
359                         $_sub_level_pages[] = array('url' => $_base_path . $child, 'title' => $_page_title, 'has_children' => isset($_pages[$child]['children']));
360                 }
361         } else if (isset($_pages[$current_page]['parent'])) {
362                 // no children
363
364                 $parent_page = $_pages[$current_page]['parent'];
365                 return get_sub_navigation($parent_page);
366         }
367
368         return $_sub_level_pages;
369 }
370
371 function get_current_sub_navigation_page($current_page) {
372         global $_pages, $_base_path;
373
374         $parent_page = $_pages[$current_page]['parent'];
375
376         if (isset($parent_page) && defined($parent_page)) {
377                 return $_base_path . $current_page;
378         } else {
379                 return $_base_path . $current_page;
380         }
381 }
382
383 function get_path($current_page) {
384         global $_pages, $_base_path;
385
386         $parent_page = $_pages[$current_page]['parent'];
387
388         if (isset($_pages[$current_page]['title'])) {
389                 $_page_title = $_pages[$current_page]['title'];
390         } else {
391                 $_page_title = _AT($_pages[$current_page]['title_var']);
392         }
393
394         if (isset($parent_page) && defined($parent_page)) {
395                 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
396                 return $path;
397         } else if (isset($parent_page)) {
398                 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
399                 $path = array_merge((array) $path, get_path($parent_page));
400         } else {
401                 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
402         }
403         
404         return $path;
405 }
406
407 function get_home_navigation() {
408         global $_pages, $_base_path;
409
410         $home_links = array();
411         foreach ($_pages[AT_NAV_HOME] as $child) {
412                 if (isset($_pages[$child])) {
413                         if (isset($_pages[$child]['title'])) {
414                                 $title = $_pages[$child]['title'];
415                         } else {
416                                 $title = _AT($_pages[$child]['title_var']);
417                         }
418                         $home_links[] = array('url' => $_base_path . url_rewrite($child), 'title' => $title, 'img' => $_base_path.$_pages[$child]['img']);
419                 }
420         }
421
422         return $home_links;
423 }
424 ?>