SVN tag for release should only contain scripts in "docs" folder without "mods",...
[atutor.git] / docs / content.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2009                                                                              */
6 /* Inclusive Design Institute                                   */
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 define('AT_INCLUDE_PATH', 'include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16
17 $cid = $_GET['cid'] = intval($_GET['cid']);
18
19 if ($cid == 0) {
20         header('Location: '.$_base_href.'index.php');
21         exit;
22 }
23
24 /* show the content page */
25 $result = $contentManager->getContentPage($cid);
26
27 if (!($content_row = mysql_fetch_assoc($result))) {
28         $_pages['content.php']['title_var'] = 'missing_content';
29         $_pages['content.php']['parent']    = 'index.php';
30         $_pages['content.php']['ignore']        = true;
31
32
33         require(AT_INCLUDE_PATH.'header.inc.php');
34
35         $msg->addError('PAGE_NOT_FOUND');
36         $msg->printAll();
37
38         require (AT_INCLUDE_PATH.'footer.inc.php');
39         exit;
40 } /* else: */
41
42 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
43         $course_base_href = 'get.php/';
44 } else {
45         $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
46 }
47
48 /* the "heading navigation": */
49 $path   = $contentManager->getContentPath($cid);
50
51 if ($content_row['content_path']) {
52         $content_base_href = $content_row['content_path'].'/';
53 }
54
55 $parent_headings = '';
56 $num_in_path = count($path);
57
58 /* the page title: */
59 $page_title = '';
60 $page_title .= $content_row['title'];
61
62 for ($i=0; $i<$num_in_path; $i++) {
63         $content_info = $path[$i];
64         if ($_SESSION['prefs']['PREF_NUMBERING']) {
65                 if ($contentManager->_menu_info[$content_info['content_id']]['content_parent_id'] == 0) {
66                         $top_num = $contentManager->_menu_info[$content_info['content_id']]['ordering'];
67                         $parent_headings .= $top_num;
68                 } else {
69                         $top_num = $top_num.'.'.$contentManager->_menu_info[$content_info['content_id']]['ordering'];
70                         $parent_headings .= $top_num;
71                 }
72                 if ($_SESSION['prefs']['PREF_NUMBERING']) {
73                         $path[$i]['content_number'] = $top_num . ' ';
74                 }
75                 $parent_headings .= ' ';
76         }
77 }
78
79 if ($_SESSION['prefs']['PREF_NUMBERING']) {
80         if ($top_num != '') {
81                 $top_num = $top_num.'.'.$content_row['ordering'];
82                 $page_title .= $top_num.' ';
83         } else {
84                 $top_num = $content_row['ordering'];
85                 $page_title .= $top_num.' ';
86         }
87 }
88
89 $parent = 0;
90
91 foreach ($path as $i=>$page) {
92         // When login is a student, remove content folder from breadcrumb path as content folders are
93         // just toggles for students. Keep content folder in breadcrumb path for instructors as they
94         // can edit content folder title. 
95         if (!authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN) && 
96             $contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER) {
97                 unset($path[$i]);
98                 continue;
99         }
100         
101         if ($contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER)
102                 $content_url = 'mods/_core/editor/edit_content_folder.php?cid='.$page['content_id'];
103         else
104                 $content_url = 'content.php?cid='.$page['content_id'];
105                 
106         if (!$parent) {
107                 $_pages[$content_url]['title']    = $page['content_number'] . $page['title'];
108                 $_pages[$content_url]['parent']   = 'index.php';
109         } else {
110                 $_pages[$content_url]['title']    = $page['content_number'] . $page['title'];
111                 $_pages[$content_url]['parent']   = 'mods/_core/editor/edit_content_folder.php?cid='.$parent;
112         }
113
114         $_pages[$content_url]['ignore'] = true;
115         $parent = $page['content_id'];
116 }
117 $last_page = array_pop($_pages);
118 $_pages['content.php'] = $last_page;
119
120 reset($path);
121 $first_page = current($path);
122
123 /* the content test extension page */
124 $content_test_ids = array();    //the html
125 $content_test_rs = $contentManager->getContentTestsAssoc($cid);
126 while ($content_test_row = mysql_fetch_assoc($content_test_rs)){
127         $content_test_ids[] = $content_test_row;
128 }
129
130 /*TODO***************BOLOGNA***************REMOVE ME**********/
131 /* the content forums extension page*/
132 $content_forum_ids = array();   //the html
133 $content_forum_rs = $contentManager->getContentForumsAssoc($cid);
134 while ($content_forum_row = mysql_fetch_assoc($content_forum_rs)){
135         $content_forum_ids[] = $content_forum_row;
136 }
137
138 // use any styles that were part of the imported document
139 // $_custom_css = $_base_href.'headstuff.php?cid='.$cid.SEP.'path='.urlEncode($_base_href.$course_base_href.$content_base_href);
140
141 if ($content_row['use_customized_head'] && strlen($content_row['head']) > 0)
142 {
143         $_custom_head .= $content_row['head'];
144 }
145
146 global $_custom_head;
147 $_custom_head .= '
148         <script language="javascript" type="text/javascript">
149         //<!--
150         jQuery(function() {
151         jQuery(\'a.tooltip\').tooltip( { showBody: ": ", showURL: false } );
152         } );
153         //-->
154         </script>
155 ';
156
157 save_last_cid($cid);
158
159 if (isset($top_num) && $top_num != (int) $top_num) {
160         $top_num = substr($top_num, 0, strpos($top_num, '.'));
161 }
162 // used by header.inc.php
163 $_tool_shortcuts = $contentManager->getToolShortcuts($content_row);
164
165 /* if i'm an admin then let me see content, otherwise only if released */
166 $released_status = $contentManager->isReleased($cid);
167
168 if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
169         //if it has test and forum associated with it, still display it even if the content is empty
170         if ($content_row['text'] == '' && (empty($content_test_ids) && empty($content_forum_ids))){
171                 $msg->addInfo('NO_PAGE_CONTENT');
172                 $savant->assign('body', '');
173         } else {
174                 if ($released_status !== TRUE) {
175                         /* show the instructor that this content hasn't been released yet */
176                         $infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
177                         $msg->addInfo($infos);
178                         unset($infos);
179                 }
180
181                 $pre_test_id = $contentManager->getPretest($cid);
182                 
183                 if (intval($pre_test_id) > 0)
184                 {
185                         if (authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
186                                 $msg->addInfo('PRETEST');
187                         }
188                         else {
189                                 header('Location: '.url_rewrite('mods/_standard/tests/test_intro.php?tid='.$pre_test_id.SEP.'cid='.$cid, AT_PRETTY_URL_IS_HEADER));
190                                 exit;
191                         }
192                 }
193                 
194                 // if one of the prerequisite test(s) has expired, student cannot view the content 
195                 if (intval($pre_test_id) != -1 || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
196                 {
197                         // find whether the body has alternatives defined
198                         list($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative)
199                         = provide_alternatives($cid, $content_row['text'], true);
200                         
201                         // apply alternatives
202                         if (intval($_GET['alternative']) > 0) {
203                                 $content = provide_alternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
204                         } else {
205                                 $content = provide_alternatives($cid, $content_row['text']);
206                         }
207                         $content = format_content($content, $content_row['formatting'], $glossary);
208                         
209                         $content_array = get_content_table($content);
210                         
211                         // Create the array of alternative information for generating the AFA tool bar
212                         $alt_infos = array();
213                         $pause_image = find_image("pause.png");
214                         
215                         if($has_text_alternative){
216                                 $alt_infos['has_text_alternative'] = array('3', _AT('apply_text_alternatives'), _AT('stop_apply_text_alternatives'), $pause_image, find_image('text_alternative.png'));
217                         }
218                         if($has_audio_alternative){
219                                 $alt_infos['has_audio_alternative'] = array('1', _AT('apply_audio_alternatives'), _AT('stop_apply_audio_alternatives'), $pause_image, find_image('audio_alternative.png'));
220                         }
221                         if($has_visual_alternative){
222                                 $alt_infos['has_visual_alternative'] = array('4', _AT('apply_visual_alternatives'), _AT('stop_apply_visual_alternatives'), $pause_image, find_image('visual_alternative.png'));
223                         }
224                         if($has_sign_lang_alternative){
225                                 $alt_infos['has_sign_lang_alternative'] = array('2', _AT('apply_sign_lang_alternatives'), _AT('stop_apply_sign_lang_alternatives'), $pause_image, find_image('sign_lang_alternative.png'));
226                         }
227                         
228                         $savant->assign('content_table', $content_array[0]);
229                         $savant->assign('body', $content_array[1]);
230                         $savant->assign('cid', $cid);
231                         $savant->assign('alt_infos', $alt_infos);
232                         
233                         //assign test pages if there are tests associated with this content page
234                         if (!empty($content_test_ids)){
235                                 $savant->assign('test_message', $content_row['test_message']);
236                                 $savant->assign('test_ids', $content_test_ids);
237                         } else {
238                                 $savant->assign('test_message', '');
239                                 $savant->assign('test_ids', array());
240                         }
241         
242                         /*TODO***************BOLOGNA***************REMOVE ME**********/
243                         //assign forum pages if there are forums associated with this content page
244                         if (!empty($content_forum_ids)){
245                                 $savant->assign('forum_message','');
246                                 $savant->assign('forum_ids', $content_forum_ids);
247                         } else {
248                                 $savant->assign('forum_message', '');
249                                 $savant->assign('forum_ids', array());
250                         }
251
252                         // get the content that the standard and add-on modules want to display on the content page
253                         $module_status_bits = AT_MODULE_STATUS_ENABLED;
254                         $module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
255                         
256                         $module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
257                         $module_contents = '';
258                         foreach($module_list as $key=>$obj) {
259                                 $module_content = $obj->getContent($cid);
260                                 if (!empty($module_content)){
261                                         $module_contents .= '<div id="'.str_replace('/', '-', $key).'" class="content-from-module">'.$module_content.'</div>';
262                                 }
263                         }
264                         if ($module_contents <> '') $savant->assign('module_contents', $module_contents);
265                 }       
266         }
267 } else {
268         $infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
269         $msg->addInfo($infos);
270         unset($infos);
271 }
272
273 $savant->assign('content_info', _AT('page_info', AT_date(_AT('inbox_date_format'), $content_row['last_modified'], AT_DATE_MYSQL_DATETIME), $content_row['revision'], AT_date(_AT('inbox_date_format'), $content_row['release_date'], AT_DATE_MYSQL_DATETIME)));
274
275 require(AT_INCLUDE_PATH.'header.inc.php');
276
277 $savant->display('content.tmpl.php');
278
279 //save last visit page.
280 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
281
282 require (AT_INCLUDE_PATH.'footer.inc.php');
283 ?>