2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 global $system_courses;
19 5 sections: public, my_start_page, course, admin, home
21 if (isset($_pages[AT_NAV_ADMIN])) {
22 array_unshift($_pages[AT_NAV_ADMIN], 'admin/index.php');
25 if($_config['allow_browse'] && $_config['just_social'] != "1") {
26 if($_SESSION['valid_user']){
27 $browse_tab = "users/browse.php";
29 $browse_tab = "browse.php";
32 if($_config['allow_registration']) {
33 $reg_tab = "registration.php";
36 if($_config['just_social']) {
38 $_pages[AT_NAV_START] = array_merge(array('users/profile.php', 'users/preferences.php'), (isset($_pages[AT_NAV_START]) ? (array) $_pages[AT_NAV_START] : array()));
42 $_pages[AT_NAV_START] = array_merge(array('users/index.php' , $browse_tab, 'users/profile.php', 'users/preferences.php'), (isset($_pages[AT_NAV_START]) ? (array) $_pages[AT_NAV_START] : array()));
45 $_pages[AT_NAV_PUBLIC] = array_merge(array('login.php',$reg_tab,$browse_tab), (isset($_pages[AT_NAV_PUBLIC]) ? $_pages[AT_NAV_PUBLIC] : array()));
48 //$_pages[AT_NAV_START] = array_merge(array($my_tab , 'users/profile.php', 'users/preferences.php'), (isset($_pages[AT_NAV_START]) ? (array) $_pages[AT_NAV_START] : array()));
49 //The following line is needed to add MyCourses to the main nav tabs, but other adaptations are needed to have this function properly
50 //$_pages[AT_NAV_COURSE] = array('users/index.php','index.php');
51 $_pages[AT_NAV_COURSE] = array('index.php');
52 $_pages[AT_NAV_HOME] = array();
54 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) {
55 $main_links = $home_links = $side_menu = array();
57 if ($system_courses[$_SESSION['course_id']]['main_links']) {
58 $main_links = explode('|', $system_courses[$_SESSION['course_id']]['main_links']);
59 foreach ($main_links as $link) {
60 if (isset($_pages[$link])) {
61 $_pages[$link]['parent'] = AT_NAV_COURSE;
64 $_pages[AT_NAV_COURSE] = array_merge($_pages[AT_NAV_COURSE], $main_links);
67 if ($system_courses[$_SESSION['course_id']]['home_links']) {
68 $home_links = explode('|', $system_courses[$_SESSION['course_id']]['home_links']);
69 foreach ($home_links as $link) {
70 if (isset($_pages[$link])) {
71 $_pages[AT_NAV_HOME][] = $link;
76 if (authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)) {
77 $_pages[AT_NAV_COURSE][] = 'tools/index.php';
78 } else if ($_SESSION['privileges']) {
81 * the loop and all this module priv checking is done to hide the Manage tab
82 * when this student has privileges, but no items linked from the Manage tab.
83 * Example: the File Storage privilege does not have a Manage tab item.
84 * In the best case it stops after the first found link.
85 * In the worst case it goes through all the modules and doesn't find a link.
87 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);
88 $keys = array_keys($module_list);
90 foreach ($keys as $module_name) {
91 $module =& $module_list[$module_name];
92 if ($module->getPrivilege() && authenticate($module->getPrivilege(), AT_PRIV_RETURN) && ($module->getChildPage('tools/index.php'))) {
93 $_pages[AT_NAV_COURSE][] = 'tools/index.php';
98 } else if (isset($_SESSION['course_id']) && $_SESSION['course_id'] == -1) {
100 $_pages['admin/index.php']['title_var'] = 'admin_home';
101 $_pages['admin/index.php']['parent'] = AT_NAV_ADMIN;
102 $_pages['admin/index.php']['guide'] = 'admin/?p=configuration.php';
103 $_pages['admin/index.php']['children'] = array_merge(array('mods/_core/users/admins/my_edit.php', 'mods/_core/users/admins/my_password.php'), isset($_pages['mods/_core/users/index.php']['children']) ? $_pages['admin/index.php']['children'] : array());
105 $_pages['mods/_core/users/admins/my_edit.php']['title_var'] = 'my_account';
106 $_pages['mods/_core/users/admins/my_edit.php']['parent'] = 'admin/index.php';
107 $_pages['mods/_core/users/admins/my_edit.php']['guide'] = 'admin/?p=my_account.php';
109 $_pages['mods/_core/users/admins/my_password.php']['title_var'] = 'change_password';
110 $_pages['mods/_core/users/admins/my_password.php']['parent'] = 'admin/index.php';
112 if (admin_authenticate(AT_ADMIN_PRIV_ADMIN, AT_PRIV_RETURN)) {
113 //hide system preference from non-super admins
114 $_pages[AT_NAV_ADMIN][] = 'admin/config_edit.php';
116 $_pages['admin/config_edit.php']['title_var'] = 'system_preferences';
117 $_pages['admin/config_edit.php']['parent'] = AT_NAV_ADMIN;
118 $_pages['admin/config_edit.php']['guide'] = 'admin/?p=system_preferences.php';
119 $_pages['admin/config_edit.php']['children'] = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/error_logging.php','mods/_standard/social/index_admin.php'));
121 $_pages['admin/fix_content.php']['title_var'] = 'fix_content_ordering';
122 $_pages['admin/fix_content.php']['parent'] = 'admin/index.php';
124 $_pages['admin/error_logging.php']['title_var'] = 'error_logging';
125 $_pages['admin/error_logging.php']['parent'] = 'admin/config_edit.php';
126 $_pages['admin/error_logging.php']['guide'] = 'admin/?p=error_logging.php';
127 $_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());
129 $_pages['admin/error_logging_reset.php']['title_var'] = 'reset_log';
130 $_pages['admin/error_logging_reset.php']['parent'] = 'admin/error_logging.php';
132 $_pages['admin/error_logging_bundle.php']['title_var'] = 'report_errors';
133 $_pages['admin/error_logging_bundle.php']['parent'] = 'admin/error_logging.php';
135 $_pages['admin/error_logging_details.php']['title_var'] = 'viewing_profile_bugs';
136 $_pages['admin/error_logging_details.php']['parent'] = 'admin/error_logging.php';
138 $_pages['admin/error_logging_view.php']['title_var'] = 'viewing_errors';
139 $_pages['admin/error_logging_view.php']['parent'] = 'admin/error_logging_details.php';
141 if (admin_authenticate(AT_ADMIN_PRIV_ADMIN, TRUE)) {
142 // hide modules from non-super admins
143 $_pages['admin/cron_config.php']['title_var'] = 'cron_config';
144 $_pages['admin/cron_config.php']['parent'] = 'admin/config_edit.php';
145 $_pages['admin/cron_config.php']['guide'] = 'admin/?p=cron_setup.php';
146 $_pages['admin/config_edit.php']['children'] = array_merge((array) $_pages['admin/config_edit.php']['children'], array('admin/cron_config.php'));
151 $_pages['about.php']['title_var'] = 'about_atutor';
153 $_pages['404.php']['title_var'] = '404';
155 $_pages['help/index.php']['title_var'] = 'help';
156 $_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());
158 $_pages['help/accessibility.php']['title_var'] = 'accessibility';
159 $_pages['help/accessibility.php']['parent'] = 'help/index.php';
161 $_pages['help/contact_support.php']['title_var'] = 'contact_support';
162 $_pages['help/contact_support.php']['parent'] = 'help/index.php';
165 $_pages['contact_instructor.php']['title_var'] = 'contact_instructor';
169 $_pages['registration.php']['title_var'] = 'register';
170 $_pages['registration.php']['parent'] = AT_NAV_PUBLIC;
171 $_pages['registration.php']['children'] = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
172 $_pages['registration.php']['guide'] = 'general/?p=register.php';
174 $_pages['browse.php']['title_var'] = 'browse_courses';
175 $_pages['browse.php']['parent'] = AT_NAV_PUBLIC;
176 $_pages['browse.php']['children'] = isset($_pages['browse.php']['children']) ? $_pages['browse.php']['children'] : array();
177 $_pages['browse.php']['guide'] = 'general/?p=browse_courses.php';
179 $_pages['login.php']['title_var'] = 'login';
180 $_pages['login.php']['parent'] = AT_NAV_PUBLIC;
181 $_pages['login.php']['children'] = array_merge(array('password_reminder.php'), isset($_pages['login.php']['children']) ? $_pages['login.php']['children'] : array());
182 $_pages['login.php']['guide'] = 'general/?p=login.php';
184 $_pages['confirm.php']['title_var'] = 'confirm';
185 $_pages['confirm.php']['parent'] = AT_NAV_PUBLIC;
187 $_pages['password_reminder.php']['title_var'] = 'password_reminder';
188 $_pages['password_reminder.php']['parent'] = 'login.php';
189 $_pages['password_reminder.php']['guide'] = 'general/?p=password_reminder.php';
191 $_pages['logout.php']['title_var'] = 'logout';
192 $_pages['logout.php']['parent'] = AT_NAV_PUBLIC;
194 /* my start page pages */
195 $_pages['users/index.php']['title_var'] = 'my_courses';
196 $_pages['users/index.php']['parent'] = AT_NAV_START;
197 $_pages['users/index.php']['guide'] = 'general/?p=my_courses.php';
198 if (isset($_SESSION['member_id']) && $_SESSION['member_id'] && (!isset($_SESSION['course_id']) || !$_SESSION['course_id'])) {
199 //$_pages['users/index.php']['children'] = array_merge(array('mods/_core/courses/users/create_course.php'), isset($_pages['users/index.php']['children']) ? $_pages['users/index.php']['children'] : array());
201 $_pages['users/browse.php']['title_var'] = 'browse_courses';
202 //$_pages['users/browse.php']['parent'] = 'users/index.php';
203 $_pages['users/browse.php']['parent'] = AT_NAV_START;
204 $_pages['users/browse.php']['guide'] = 'general/?p=browse_courses.php';
207 if (isset($_SESSION['member_id']) && get_instructor_status() === TRUE)
209 $_pages['mods/_core/courses/users/create_course.php']['title_var'] = 'create_course';
210 $_pages['mods/_core/courses/users/create_course.php']['parent'] = 'users/index.php';
211 $_pages['mods/_core/courses/users/create_course.php']['guide'] = 'instructor/?p=creating_courses.php';
212 $_pages['users/index.php']['children'] = array_merge(array('mods/_core/courses/users/create_course.php'), isset($_pages['users/index.php']['children']) ? $_pages['users/index.php']['children'] : array());
215 else if (isset($_SESSION['member_id']) && ALLOW_INSTRUCTOR_REQUESTS)
218 $_pages['mods/_core/courses/users/create_course.php']['title_var'] = 'request_instructor_priv';
219 $_pages['mods/_core/courses/users/create_course.php']['parent'] = 'users/index.php';
220 $_pages['mods/_core/courses/users/create_course.php']['guide'] = 'instructor/?p=creating_courses.php';
221 $_pages['users/index.php']['children'] = array_merge(array('mods/_core/courses/users/create_course.php'), isset($_pages['users/index.php']['children']) ? $_pages['users/index.php']['children'] : array());
225 $_pages['users/private_enroll.php']['title_var'] = 'enroll';
226 $_pages['users/private_enroll.php']['parent'] = 'users/index.php';
228 $_pages['users/remove_course.php']['title_var'] = 'unenroll';
229 $_pages['users/remove_course.php']['parent'] = 'users/index.php';
231 $_pages['mods/_standard/profile_pictures/profile_picture.php']['title_var'] = 'picture';
233 $_pages['users/profile.php']['title_var'] = 'profile';
234 $_pages['users/profile.php']['parent'] = AT_NAV_START;
235 $_pages['users/profile.php']['guide'] = 'general/?p=profile.php';
236 //$_pages['users/profile.php']['children'] = array_merge(array('users/password_change.php', 'users/email_change.php','mods/_standard/profile_pictures/profile_picture.php'), (array) $_pages['users/profile.php']['children']);
237 $_pages['users/profile.php']['children'] = array_merge(array('users/password_change.php', 'users/email_change.php','mods/_standard/profile_pictures/profile_picture.php'), (array) $_pages['users/profile.php']['children']);
239 $_pages['users/password_change.php']['title_var'] = 'change_password';
240 $_pages['users/password_change.php']['parent'] = 'users/profile.php';
241 //$_pages['users/password_change.php']['guide'] = 'instructor/?p=creating_courses.php';
243 $_pages['users/email_change.php']['title_var'] = 'change_email';
244 $_pages['users/email_change.php']['parent'] = 'users/profile.php';
246 $_pages['users/preferences.php']['title_var'] = 'preferences';
247 $_pages['users/preferences.php']['parent'] = AT_NAV_START;
248 $_pages['users/preferences.php']['guide'] = 'general/?p=preferences.php';
250 $_pages['users/pref_wizard/index.php']['title_var'] = 'preferences';
251 $_pages['users/pref_wizard/index.php']['parent'] = AT_NAV_START;
253 $_pages['enroll.php']['title_var'] = 'enroll';
254 $_pages['enroll.php']['parent'] = 'users/browse.php';
257 $_pages['index.php']['title_var'] = 'course_home';
258 $_pages['index.php']['parent'] = AT_NAV_COURSE;
260 /* instructor pages: */
261 $_pages['tools/index.php']['title_var'] = 'manage';
262 $_pages['tools/index.php']['parent'] = AT_NAV_COURSE;
264 $_pages['inbox/index.php']['title_var'] = 'inbox';
265 $_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());
267 $_pages['inbox/sent_messages.php']['title_var'] = 'sent_messages';
268 $_pages['inbox/sent_messages.php']['parent'] = 'inbox/index.php';
270 $_pages['inbox/send_message.php']['title_var'] = 'send_message';
271 $_pages['inbox/send_message.php']['parent'] = 'inbox/index.php';
273 $_pages['inbox/export.php']['title_var'] = 'export';
274 $_pages['inbox/export.php']['parent'] = 'inbox/index.php';
276 $_pages['profile.php']['title_var'] = 'profile';
277 $_pages['profile.php']['parent'] = 'index.php';
280 * Iterate $_pages, distribute the "avail_in_mobile" setting on the parent page to all its child pages
281 * as long as it's not initially set on the child page.
282 * @param $this_page - string, the page location used as a key in $_pages
284 function distribute_avail_in_mobile($this_page) {
286 // return in the cases:
287 // 1. the given page is not defined in $_pages
288 // 2. it does not have any child
289 // 3. the given page does not have "avail_in_mobile" setting defined
290 if (!isset($_pages[$this_page]) || !isset($_pages[$this_page]["avail_in_mobile"]) ||
291 !isset($_pages[$this_page]['children']) || !is_array($_pages[$this_page]['children'])) {
295 foreach ($_pages[$this_page]['children'] as $child_page) {
296 // Initial "avail_in_mobile" setting on the child page wins over the one fromt the parent
297 if (!isset($_pages[$child_page])) {
300 if (!isset($_pages[$child_page]["avail_in_mobile"])) {
301 $_pages[$child_page]["avail_in_mobile"] = $_pages[$this_page]["avail_in_mobile"];
303 distribute_avail_in_mobile($child_page);
308 // The page can be turned on/off in mobile themes by adjusting page setting "avail_in_mobile" in module.php
309 // Here is to populate this setting to child pages.
310 if (is_mobile_device()) {
311 foreach ($_pages as $page => $garbage) {
312 distribute_avail_in_mobile($page);
316 $current_page = substr($_SERVER['PHP_SELF'], strlen($_base_path));
318 function get_num_new_messages() {
320 static $num_messages;
322 if (isset($num_messages)) {
323 return $num_messages;
325 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND new=1";
326 $result = mysql_query($sql, $db);
327 $row = mysql_fetch_assoc($result);
328 $num_messages = $row['cnt'];
330 return $num_messages;
334 * Check the page availability
335 * The page is unavailable if it's accessed by mobile device and the setting "avail_in_mobile" is set to false
336 * @param $this_page - string, the page location used as a key in $_pages
338 function page_available($this_page) {
340 if (is_mobile_device() && isset($_pages[$this_page]["avail_in_mobile"]) && !$_pages[$this_page]["avail_in_mobile"]) {
343 return isset($_pages[$this_page]);
347 //TODO****************BOLOGNA*******************REMOVE ME**********************/
348 function get_main_navigation($current_page) {
349 global $_pages, $_base_path, $_tool;
351 $parent_page = $_pages[$current_page]['parent'];
352 $_top_level_pages = array();
354 $tool_file= $table = '';
356 if (isset($parent_page) && defined($parent_page)) {
357 foreach($_pages[$parent_page] as $page) {
358 if (page_available($page)) {
359 if (isset($_pages[$page]['title'])) {
360 $_page_title = $_pages[$page]['title'];
362 $_page_title = _AT($_pages[$page]['title_var']);
365 if(isset($_tool[$_pages[$page]['title_var']])){ //viene prelevato il file nel caso in cui lo strumento sia valodo per essere inserito nella toolbar in fase di editing dei conenuti del corso
366 $tool_file = $_tool[$_pages[$page]['title_var']]['file'];
367 $table = $_tool[$_pages[$page]['title_var']]['table'];
373 $_top_level_pages[] = array('url' => $_base_path . url_rewrite($page), 'title' => $_page_title, 'img' => $_base_path.$_pages[$page]['img'], 'tool_file' => $tool_file, 'table' => $table);
376 } else if (isset($parent_page)) {
377 return get_main_navigation($parent_page);
380 return $_top_level_pages;
383 function get_current_main_page($current_page) {
384 global $_pages, $_base_path;
385 $parent_page = $_pages[$current_page]['parent'];
387 if (isset($parent_page) && defined($parent_page)) {
388 return $_base_path . url_rewrite($current_page);
389 } else if (isset($parent_page)) {
390 return get_current_main_page($parent_page);
394 function get_sub_navigation($current_page) {
395 global $_pages, $_base_path;
397 if (isset($current_page) && defined($current_page)) {
400 } else if (isset($_pages[$current_page]['children']) && page_available($current_page)) {
401 if (isset($_pages[$current_page]['title'])) {
402 $_page_title = $_pages[$current_page]['title'];
404 $_page_title = _AT($_pages[$current_page]['title_var']);
407 $_sub_level_pages[] = array('url' => $_base_path . $current_page, 'title' => $_page_title);
408 foreach ($_pages[$current_page]['children'] as $child) {
409 if (!page_available($child)) continue;
411 if (isset($_pages[$child]['title'])) {
412 $_page_title = $_pages[$child]['title'];
414 $_page_title = _AT($_pages[$child]['title_var']);
417 $_sub_level_pages[] = array('url' => $_base_path . $child, 'title' => $_page_title, 'has_children' => isset($_pages[$child]['children']));
419 } else if (isset($_pages[$current_page]['parent'])) {
422 $parent_page = $_pages[$current_page]['parent'];
423 return get_sub_navigation($parent_page);
426 return $_sub_level_pages;
429 function get_current_sub_navigation_page($current_page) {
430 global $_pages, $_base_path;
432 if (!page_available($current_page)) return;
434 $parent_page = $_pages[$current_page]['parent'];
436 if (isset($parent_page) && defined($parent_page)) {
437 return $_base_path . $current_page;
439 return $_base_path . $current_page;
443 function get_path($current_page) {
444 global $_pages, $_base_path;
448 if (!page_available($current_page)){
452 $parent_page = $_pages[$current_page]['parent'];
454 if (isset($_pages[$current_page]['title'])) {
455 $_page_title = $_pages[$current_page]['title'];
457 $_page_title = _AT($_pages[$current_page]['title_var']);
460 if (isset($parent_page) && defined($parent_page)) {
461 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
463 } else if (isset($parent_page)) {
464 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
465 $path = array_merge((array) $path, get_path($parent_page));
467 $path[] = array('url' => $_base_path . url_rewrite($current_page), 'title' => $_page_title);
473 //TODO****************BOLOGNA*********************REMOVE ME*****************/
474 function get_home_navigation($home_array='') {
475 global $_pages, $_list, $_base_path, $_tool;
477 // set default home_array to course index navigation array
478 if (!is_array($home_array)) $home_array = $_pages[AT_NAV_HOME];
480 $home_links = array();
481 foreach ($home_array as $child) { //esecuzione del ciclo fin quando non saranno terminati i moduli presenti nella home-page del corso
482 if (page_available($child)) {
484 $title = $icon = $sub_file = $image = $text = $tool_file = $table ='';
486 if (isset($_pages[$child]['title'])) { //viene prelevato il titolo che dovr� poi essere utilizzato nella visualizzazione
487 $title = $_pages[$child]['title'];
489 $title = _AT($_pages[$child]['title_var']);
491 if(isset($_pages[$child]['icon'])) { //si controlla se è presente l'icona inserita nel modulo di rifrimento. si ricorda che l'icona � inserita solo per i moduli che prevedono possibili sottocontenuti.
492 $icon = $_base_path.$_pages[$child]['icon']; //in caso positivo viene prelevata e inserita in una variabile di appoggio che poi sar� a sua volta inserita all'interno dell'array finale home_links[]
494 if(isset($_pages[$child]['text'])) { //nel caso in cui non sia presente un' icona associata si controlla se � stato settata il testo (per moduli privi di sottocontenuti).
495 $text = $_pages[$child]['text']; //il testo viene inserito in una variabile d'appoggio e successivamente nell'array.
498 if (isset($_list[$_pages[$child]['title_var']])) //viene prelevato il path del file che dovr� poi essere richiamato nella visualizzazione dei sottocontenuti. solo i moduli che prevedono sottocontenuti avranno un file di riferimento.
499 $sub_file = $_list[$_pages[$child]['title_var']]['file'];
501 if(isset($_tool[$_pages[$child]['title_var']])){ //viene prelevato il file nel caso in cui lo strumento sia valido per essere inserito nella toolbar in fase di editing dei conenuti del corso
502 $tool_file = $_tool[$_pages[$child]['title_var']]['file'];
503 $table = $_tool[$_pages[$child]['title_var']]['table'];
506 $real_image_in_theme = AT_INCLUDE_PATH.'../themes/'.$_SESSION['prefs']['PREF_THEME'].'/'.$_pages[$child]['img'];
507 $image_in_theme = $_base_path.'themes/'.$_SESSION['prefs']['PREF_THEME'].'/'.$_pages[$child]['img'];
509 // look for images in theme folder. If not exists, use images relative to ATutor root folder
510 if (file_exists($real_image_in_theme))
511 $image = $image_in_theme;
513 $image = $_base_path.$_pages[$child]['img'];
515 // inclusion of all data necessary for displaying the modules on the home-page. Set by default to check the visible because the modules will be loaded all visible in the home.
516 $home_links[] = array('url' => $_base_path . url_rewrite($child), 'title' => $title, 'img' => $image, 'icon' => $icon, 'text' => $text, 'sub_file' => $sub_file, 'tool_file' => $tool_file, 'table' => $table);