remove old readme
[atutor.git] / include / header.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
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 /************************************************************************/
12 // $Id$
13
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15
16 //header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
17
18 //Harris Timer
19   $mtime = microtime(); 
20   $mtime = explode(' ', $mtime); 
21   $mtime = $mtime[1] + $mtime[0]; 
22   $starttime = $mtime; 
23 //Harris Timer Ends
24
25 global $myLang;
26 global $savant;
27 global $onload;
28 global $content_base_href, $course_base_href;
29 global $_base_path;
30 global $cid;
31 global $contentManager;
32 global $db;
33 global $_pages;
34 global $_stacks;
35 global $framed, $popup;
36 global $_custom_css;
37 global $_custom_head;
38 global $substr, $strlen, $_course_id;
39 global $_tool_shortcuts;
40
41 require(AT_INCLUDE_PATH . 'lib/menu_pages.php');
42 //require(AT_INCLUDE_PATH."../jscripts/opensocial/all_opensocial.php");
43
44 $savant->assign('lang_code', $_SESSION['lang']);
45 $savant->assign('lang_charset', $myLang->getCharacterSet());
46 $savant->assign('base_path', $_base_path);
47 $savant->assign('base_tmpl_path', $_SERVER['HTTP_HOST']);
48 $savant->assign('theme', $_SESSION['prefs']['PREF_THEME']);
49 $savant->assign('current_date', AT_date(_AT('announcement_date_format')));
50 $savant->assign('just_social', $_config['just_social']);
51
52 $theme_img  = $_base_path . 'themes/'. $_SESSION['prefs']['PREF_THEME'] . '/images/';
53 $savant->assign('img', $theme_img);
54
55 $_tmp_base_href = AT_BASE_HREF;
56 if (isset($course_base_href) || isset($content_base_href)) {
57         $_tmp_base_href .= $course_base_href;
58         if ($content_base_href) {
59                 $_tmp_base_href .= $content_base_href;
60         }
61 }
62
63 $savant->assign('content_base_href', $_tmp_base_href);
64 $savant->assign('base_href', AT_BASE_HREF);
65
66 //Handle pretty url pages
67 if ((($_config['course_dir_name'] + $_config['pretty_url']) > 0) && ($temp = strpos($_SERVER['PHP_SELF'], AT_PRETTY_URL_HANDLER)) > 0){
68         $current_page = $pretty_current_page; //this is set in AT_PRETTY_URL_HANDLER
69 }
70
71 if ($myLang->isRTL()) {
72         $savant->assign('rtl_css', '<link rel="stylesheet" href="'.$_base_path.'themes/'.$_SESSION['prefs']['PREF_THEME'].'/rtl.css" type="text/css" />');
73 } else {
74         $savant->assign('rtl_css', '');
75 }
76
77 $custom_head = '';
78 if (isset($_custom_css)) {
79         $custom_head = '<link rel="stylesheet" href="'.$_custom_css.'" type="text/css" />';
80 }
81
82 if (isset($_custom_head)) {
83         $custom_head .= '
84 ' . $_custom_head;
85 }
86
87 $savant->assign('custom_css', $custom_head);
88
89 if ($onload && ($_SESSION['prefs']['PREF_FORM_FOCUS'] || ($substr($onload, -8) != 'focus();'))) {
90         $savant->assign('onload', $onload);
91 }
92
93 if (isset($_SESSION['valid_user']) && $_SESSION['valid_user'] === true) {
94         if (!empty($_SESSION['member_id'])) {
95                 $savant->assign('user_name', get_display_name($_SESSION['member_id']));
96         } else {
97                 $savant->assign('user_name', $_SESSION['login']);
98         }
99 } else {
100         $savant->assign('user_name', _AT('guest'));
101 }
102
103 if (!isset($_pages[$current_page])) {
104         global $msg;
105         $msg->addError('PAGE_NOT_FOUND'); // probably the wrong error
106         header('location: '.AT_BASE_HREF.'index.php');
107         exit;
108 }
109
110 $_top_level_pages        = get_main_navigation($current_page);
111
112 $_current_top_level_page = get_current_main_page($current_page);
113
114 if (empty($_top_level_pages)) {
115         if (!$_SESSION['member_id'] && !$_SESSION['course_id']) {
116                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_PUBLIC][0]);
117         } else if ($_SESSION['course_id'] < 0) {
118                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_ADMIN][0]);
119         } else if (!$_SESSION['course_id']) {
120                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_START][0]);
121         } else {
122                 $_top_level_pages = get_main_navigation($_pages[AT_NAV_COURSE][0]);
123         }
124 }
125 $_sub_level_pages        = get_sub_navigation($current_page);
126
127 $_current_sub_level_page = get_current_sub_navigation_page($current_page);
128
129 $_path = get_path($current_page);
130
131 unset($_path[0]);
132 if (isset($_path[2]['url'], $_sub_level_pages[0]['url']) && $_path[2]['url'] == $_sub_level_pages[0]['url']) {
133         $back_to_page = $_path[3];
134 } else if (isset($_path[1]['url'], $_sub_level_pages[0]['url']) && $_path[1]['url'] == $_sub_level_pages[0]['url']) {
135         $back_to_page = isset($_path[2]) ? $_path[2] : null;
136 } else if (isset($_path[1])) {
137         $back_to_page = $_path[1];
138 }
139
140 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) {
141         $_path[] = array('url' => $_base_path . url_rewrite('index.php'), 'title' => $_SESSION['course_title']);
142 } else if (isset($_SESSION['course_id']) && $_SESSION['course_id'] < 0) {
143         $_path[] = array('url' => $_base_path . 'admin/index.php', 'title' => _AT('administration'));
144 }
145
146 if (isset($_SESSION['member_id']) && $_SESSION['member_id']) {
147         $_path[] = array('url' => $_base_path . 'bounce.php?course=0', 'title' => _AT('my_start_page'));
148 } else if (!isset($_SESSION['course_id']) || !$_SESSION['course_id']) {
149         $_path[] = array('url' => $_base_path . 'login.php', 'title' => SITE_NAME);
150 }
151
152 $_path = array_reverse($_path);
153
154 if (isset($_pages[$current_page]['title'])) {
155         $_page_title = $_pages[$current_page]['title'];
156 } else {
157         $_page_title = _AT($_pages[$current_page]['title_var']);
158 }
159
160
161
162 /* calculate the section_title: */
163 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) {
164         //Truncate course title if it's > 45.
165         $session_course_title = htmlentities($_SESSION['course_title'], ENT_QUOTES, 'UTF-8');
166         $section_title = validate_length($session_course_title, 100, VALIDATE_LENGTH_FOR_DISPLAY);
167         // If there is an icon, display it on the header
168         $sql = 'SELECT icon FROM '.TABLE_PREFIX.'courses WHERE course_id='.$_SESSION['course_id'];
169         $result =  mysql_query($sql, $db);
170         $row = mysql_fetch_assoc($result);
171         if (!empty($row['icon'])){
172                 //Check if this is a custom icon, if so, use get_course_icon.php to get it
173                 //Otherwise, simply link it from the images/
174                 $custom_icon_path = AT_CONTENT_DIR.$_SESSION['course_id']."/custom_icons/";
175                 if (file_exists($custom_icon_path.$row['icon'])) {
176                         if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
177                                 $course_icon = $_base_path.'get_course_icon.php/?id='.$_SESSION['course_id'];
178                         } else {
179                                 $course_icon = $_base_path.'content/' . $_SESSION['course_id'] . '/';
180                         }
181                 } else {
182                         $course_icon = $_base_path.'images/courses/'.$row['icon'];
183                 }
184                 $savant->assign('icon', $course_icon);
185         }
186 } else if (!isset($_SESSION['valid_user']) || !$_SESSION['valid_user']) {
187         $section_title = SITE_NAME;
188         if (defined('HOME_URL') && HOME_URL) {
189                 $_top_level_pages[] = array('url' => HOME_URL, 'title' => _AT('home'));
190         }
191 } else if ($_SESSION['course_id'] < 0) {
192         $section_title = _AT('administration');
193 } else if (!$_SESSION['course_id']) {
194         $section_title = _AT('my_start_page');
195 }
196 $savant->assign('current_top_level_page', $_current_top_level_page);
197 $savant->assign('sub_level_pages', $_sub_level_pages);
198 $savant->assign('current_sub_level_page', $_current_sub_level_page);
199
200 $savant->assign('path', $_path);
201 $savant->assign('back_to_page', isset($back_to_page) ? $back_to_page : null);
202 $savant->assign('page_title', htmlspecialchars($_page_title, ENT_COMPAT, "UTF-8"));
203 $savant->assign('top_level_pages', $_top_level_pages);
204 $savant->assign('section_title', $section_title);
205
206 if (isset($_pages[$current_page]['guide'])) {
207         $savant->assign('guide', AT_GUIDES_PATH . $_pages[$current_page]['guide']);
208 }
209
210 $myLang->sendContentTypeHeader();
211
212 if (isset($_SESSION['course_id']) && $_SESSION['course_id'] > -1) {
213
214         /* the list of our courses: */
215         /* used for the courses drop down */
216         global $system_courses;
217         if ($_SESSION['valid_user']) {
218                 $sql    = "SELECT E.course_id FROM ".TABLE_PREFIX."course_enrollment E WHERE E.member_id=$_SESSION[member_id] AND E.approved<>'n'";
219                 $result = @mysql_query($sql, $db);
220
221                 $nav_courses = array(); /* the list of courses we're enrolled in or own */
222                 while ($row = @mysql_fetch_assoc($result)) {
223                         //Truncate course title if it's > 45.
224                         $system_courses[$row['course_id']]['title'] = htmlentities($system_courses[$row['course_id']]['title'], ENT_QUOTES, 'UTF-8');
225                         $nav_courses[$row['course_id']] = validate_length($system_courses[$row['course_id']]['title'], 45, VALIDATE_LENGTH_FOR_DISPLAY);
226                 }
227
228                 natcasesort($nav_courses);
229                 reset($nav_courses);
230                 $savant->assign('nav_courses',    $nav_courses);
231         }
232
233         if (($_SESSION['course_id'] > 0) && isset($_SESSION['prefs']['PREF_JUMP_REDIRECT']) && $_SESSION['prefs']['PREF_JUMP_REDIRECT']) {
234                 $savant->assign('rel_url', $_rel_url);
235         } else {
236                 $savant->assign('rel_url', '');
237         }
238
239         /* course specific elements: */
240         /* != 'public' special case for the about.php page, which is available from a course but hides the content menu */
241         $sequence_links = array();
242         if ($_SESSION['course_id'] > 0) {
243                 $sequence_links = $contentManager->generateSequenceCrumbs($cid);
244                 $savant->assign('sequence_links', $sequence_links);
245         }
246
247         //side menu array
248         if ($_SESSION['course_id'] > 0) {
249                 $side_menu = array();
250                 $side_menu = explode('|', $system_courses[$_SESSION['course_id']]['side_menu']);
251                 $side_menu = array_intersect($side_menu, $_stacks);
252                 $savant->assign('side_menu', $side_menu);
253         }
254 }
255
256 // array of content tools for shortcuts tool bar.
257 if (isset($_tool_shortcuts)) $savant->assign('shortcuts', $_tool_shortcuts);
258
259 /* Register our Errorhandler on everypage */
260 //require_once(AT_INCLUDE_PATH . 'classes/ErrorHandler/ErrorHandler.class.php');
261 //$err = new ErrorHandler();
262
263
264 //TODO*******************BOLOGNA*******************REMOVE ME*******************/
265 // if filemanager is a inside a popup or a frame
266 // i don't like this code. i don't know were these two variables are coming from
267 // anyone can add ?framed=1 to a URL to alter the behaviour.
268
269 // global $_course_id is set when a guest accessing a public course. 
270 // This is to solve the issue that the google indexing fails as the session vars are lost.
271 if (isset($_SESSION['course_id'])) 
272         $_course_id = $_SESSION['course_id'];
273 else if (isset($_GET['p_course'])) // p_course is set when pretty url is turned on and public course is accessed
274         $_course_id = $_GET['p_course'];
275
276 $savant->assign('course_id', $_course_id);
277 $savant->assign('is_mobile_device', is_mobile_device());
278 $savant->assign('mobile_device_type', get_mobile_device_type());
279
280 if ((isset($_REQUEST['framed']) && $_REQUEST['framed']) || (isset($_REQUEST['popup']) && $_REQUEST['popup'])) {
281     $savant->assign('framed', 1);
282     $savant->assign('popup', 1);
283
284     if(isset($tool_flag) && ($tool_flag))
285         $savant->display('include/tm_header.tmpl.php');         //header for toolmanager
286     else
287         $savant->display('include/fm_header.tmpl.php');
288
289 } else {
290     //$savant->assign('opensocial', open_social_libs($_base_href));
291     $savant->display('include/header.tmpl.php');
292 }
293
294
295 ?>