tagging as ATutor 1.5.4-release
[atutor.git] / include / header.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2007 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
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16
17 header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
18
19 global $myLang;
20 global $savant;
21 global $onload;
22 global $content_base_href, $course_base_href;
23 global $_base_path;
24 global $cid;
25 global $contentManager;
26 global $db;
27 global $_pages;
28 global $_stacks;
29 global $framed, $popup;
30 global $_custom_css;
31
32 require(AT_INCLUDE_PATH . 'lib/menu_pages.php');
33
34 $savant->assign('lang_code', $_SESSION['lang']);
35 $savant->assign('lang_charset', $myLang->getCharacterSet());
36 $savant->assign('base_path', $_base_path);
37 $savant->assign('theme', $_SESSION['prefs']['PREF_THEME']);
38 $savant->assign('current_date', AT_date(_AT('announcement_date_format')));
39
40 $theme_img  = $_base_path . 'themes/'. $_SESSION['prefs']['PREF_THEME'] . '/images/';
41 $savant->assign('img', $theme_img);
42
43 $_tmp_base_href = AT_BASE_HREF;
44 if (isset($course_base_href) || isset($content_base_href)) {
45         $_tmp_base_href .= $course_base_href;
46         if ($content_base_href) {
47                 $_tmp_base_href .= $content_base_href;
48         }
49 }
50
51 $savant->assign('content_base_href', $_tmp_base_href);
52 $savant->assign('base_href', AT_BASE_HREF);
53
54 if ($myLang->isRTL()) {
55         $savant->assign('rtl_css', '<link rel="stylesheet" href="'.$_base_path.'themes/'.$_SESSION['prefs']['PREF_THEME'].'/rtl.css" type="text/css" />');
56 } else {
57         $savant->assign('rtl_css', '');
58 }
59
60 if (isset($_custom_css)) {
61         $savant->assign('custom_css', '<link rel="stylesheet" href="'.$_custom_css.'" type="text/css" />');
62 } else {
63         $savant->assign('custom_css', '');
64 }
65
66 if ($onload && ($_SESSION['prefs']['PREF_FORM_FOCUS'] || (substr($onload, -8) != 'focus();'))) {
67         $savant->assign('onload', $onload);
68 }
69
70 if ($_SESSION['valid_user'] === true) {
71         if ($_SESSION['member_id']) {
72                 $savant->assign('user_name', get_display_name($_SESSION['member_id']));
73         } else {
74                 $savant->assign('user_name', $_SESSION['login']);
75         }
76 } else {
77         $savant->assign('user_name', _AT('guest'));
78 }
79
80 $current_page = substr($_SERVER['PHP_SELF'], strlen($_base_path));
81
82 if (!isset($_pages[$current_page])) {
83         global $msg;
84         $msg->addError('PAGE_NOT_FOUND'); // probably the wrong error
85         header('location: '.AT_BASE_HREF.'index.php');
86         exit;
87 }
88
89 $_top_level_pages        = get_main_navigation($current_page);
90
91 $_current_top_level_page = get_current_main_page($current_page);
92
93 if (empty($_top_level_pages)) {
94         if (!$_SESSION['member_id'] && !$_SESSION['course_id']) {
95                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_PUBLIC][0]);
96         } else if ($_SESSION['course_id'] < 0) {
97                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_ADMIN][0]);
98         } else if (!$_SESSION['course_id']) {
99                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_START][0]);
100         } else {
101                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_COURSE][0]);
102         }
103 }
104 $_sub_level_pages        = get_sub_navigation($current_page);
105
106 $_current_sub_level_page = get_current_sub_navigation_page($current_page);
107
108 $_path = get_path($current_page);
109
110
111 unset($_path[0]);
112 if ($_path[2]['url'] == $_sub_level_pages[0]['url']) {
113         $back_to_page = $_path[3];
114 } else if ($_path[1]['url'] == $_sub_level_pages[0]['url']) {
115         $back_to_page = $_path[2];
116 } else {
117         $back_to_page = $_path[1];
118 }
119
120 if ($_SESSION['course_id'] > 0) {
121         $_path[] = array('url' => $_base_path . 'index.php', 'title' => $_SESSION['course_title']);
122 } else if ($_SESSION['course_id'] < 0) {
123         $_path[] = array('url' => $_base_path . 'admin/index.php', 'title' => _AT('administration'));
124 }
125
126 if ($_SESSION['member_id']) {
127         $_path[] = array('url' => $_base_path . 'bounce.php?course=0', 'title' => _AT('my_start_page'));
128 } else if (!$_SESSION['course_id']) {
129         $_path[] = array('url' => $_base_path . 'login.php', 'title' => SITE_NAME);
130 }
131
132 $_path = array_reverse($_path);
133 if (isset($_pages[$current_page]['title'])) {
134         $_page_title = $_pages[$current_page]['title'];
135 } else {
136         $_page_title = _AT($_pages[$current_page]['title_var']);
137 }
138
139
140
141 /* calculate the section_title: */
142 if ($_SESSION['course_id'] > 0) {
143         $section_title = $_SESSION['course_title'];
144 } else if (!$_SESSION['valid_user']) {
145         $section_title = SITE_NAME;
146         if (defined('HOME_URL') && HOME_URL) {
147                 $_top_level_pages[] = array('url' => HOME_URL, 'title' => _AT('home'));
148         }
149 } else if ($_SESSION['course_id'] < 0) {
150         $section_title = _AT('administration');
151 } else if (!$_SESSION['course_id']) {
152         $section_title = _AT('my_start_page');
153 }
154 $savant->assign('current_top_level_page', $_current_top_level_page);
155 $savant->assign('sub_level_pages', $_sub_level_pages);
156 $savant->assign('current_sub_level_page', $_current_sub_level_page);
157
158 $savant->assign('path', $_path);
159 $savant->assign('back_to_page', $back_to_page);
160 $savant->assign('page_title', $_page_title);
161 $savant->assign('top_level_pages', $_top_level_pages);
162 $savant->assign('section_title', $section_title);
163
164 if (isset($_pages[$current_page]['guide'])) {
165         $savant->assign('guide', AT_GUIDES_PATH . $_pages[$current_page]['guide']);
166 }
167
168 $myLang->sendContentTypeHeader();
169
170 if ($_SESSION['course_id'] > -1) {
171
172         /* the list of our courses: */
173         /* used for the courses drop down */
174         global $system_courses;
175         if ($_SESSION['valid_user']) {
176                 $sql    = "SELECT E.course_id FROM ".TABLE_PREFIX."course_enrollment E WHERE E.member_id=$_SESSION[member_id] AND E.approved<>'n'";
177                 $result = @mysql_query($sql, $db);
178
179                 $nav_courses = array(); /* the list of courses we're enrolled in or own */
180                 while ($row = @mysql_fetch_assoc($result)) {
181                         $nav_courses[$row['course_id']] = $system_courses[$row['course_id']]['title'];
182                 }
183
184                 natcasesort($nav_courses);
185                 reset($nav_courses);
186                 $savant->assign('nav_courses',    $nav_courses);
187         }
188
189         if (($_SESSION['course_id'] > 0) && isset($_SESSION['prefs'][PREF_JUMP_REDIRECT]) && $_SESSION['prefs'][PREF_JUMP_REDIRECT]) {
190                 $savant->assign('rel_url', $_rel_url);
191         } else {
192                 $savant->assign('rel_url', '');
193         }
194
195         /* course specific elements: */
196         /* != 'public' special case for the about.php page, which is available from a course but hides the content menu */
197         $sequence_links = array();
198         if ($_SESSION['course_id'] > 0) {
199                 $sequence_links = $contentManager->generateSequenceCrumbs($cid);
200                 $savant->assign('sequence_links', $sequence_links);
201         }
202
203         //side menu array
204         if ($_SESSION['course_id'] > 0) {
205                 $side_menu = array();
206                 $side_menu = explode('|', $system_courses[$_SESSION['course_id']]['side_menu']);
207                 $side_menu = array_intersect($side_menu, $_stacks);
208                 $savant->assign('side_menu', $side_menu);
209         }
210 }
211
212 /* Register our Errorhandler on everypage */
213 //require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
214 //$err =& new ErrorHandler();
215
216 // if filemanager is a inside a popup or a frame
217 // i don't like this code. i don't know were these two variables are coming from
218 // anyone can add ?framed=1 to a URL to alter the behaviour.
219 if ($_REQUEST['framed'] || $_REQUEST['popup']) {
220         $savant->assign('framed', 1);
221         $savant->assign('popup', 1);
222         $savant->display('include/fm_header.tmpl.php');
223 } else {
224         $savant->display('include/header.tmpl.php');
225 }
226
227 ?>