moved code up one level to eliminate the docs subdirectory
[acontent.git] / home / course / content.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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
13 define('TR_INCLUDE_PATH', '../../include/');
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
16 require_once(TR_INCLUDE_PATH.'classes/DAO/ContentForumsAssocDAO.class.php');
17
18 global $_current_user, $_course_id, $_content_id, $contentManager;
19
20 $cid = $_content_id;
21
22 if ($cid == 0) {
23         header('Location: '.$_base_href.'index.php');
24         exit;
25 }
26 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
27         $_SESSION['course_id'] = $_course_id;  // used by get.php
28 }
29
30 /* show the content page */
31 if (isset($contentManager)) $content_row = $contentManager->getContentPage($cid);
32
33 if (!$content_row || !isset($contentManager)) {
34         $_pages['home/course/content.php']['title_var'] = 'missing_content';
35         $_pages['home/course/content.php']['parent']    = 'home/index.php';
36         $_pages['home/course/content.php']['ignore']    = true;
37
38
39         require(TR_INCLUDE_PATH.'header.inc.php');
40
41         $msg->addError('MISSING_CONTENT');
42         $msg->printAll();
43
44         require (TR_INCLUDE_PATH.'footer.inc.php');
45         exit;
46 } /* else: */
47
48 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
49         $course_base_href = 'get.php/';
50 } else {
51         $course_base_href = 'content/' . $_course_id . '/';
52 }
53
54 /* the "heading navigation": */
55 $path   = $contentManager->getContentPath($cid);
56
57 if ($content_row['content_path']) {
58         $content_base_href = $content_row['content_path'].'/';
59 }
60
61 $parent_headings = '';
62 $num_in_path = count($path);
63
64 /* the page title: */
65 $page_title = '';
66 $page_title .= $content_row['title'];
67
68 for ($i=0; $i<$num_in_path; $i++) {
69         $content_info = $path[$i];
70         if ($_SESSION['prefs']['PREF_NUMBERING']) {
71                 if ($contentManager->_menu_info[$content_info['content_id']]['content_parent_id'] == 0) {
72                         $top_num = $contentManager->_menu_info[$content_info['content_id']]['ordering'];
73                         $parent_headings .= $top_num;
74                 } else {
75                         $top_num = $top_num.'.'.$contentManager->_menu_info[$content_info['content_id']]['ordering'];
76                         $parent_headings .= $top_num;
77                 }
78                 if ($_SESSION['prefs']['PREF_NUMBERING']) {
79                         $path[$i]['content_number'] = $top_num . ' ';
80                 }
81                 $parent_headings .= ' ';
82         }
83 }
84
85 if ($_SESSION['prefs']['PREF_NUMBERING']) {
86         if ($top_num != '') {
87                 $top_num = $top_num.'.'.$content_row['ordering'];
88                 $page_title .= $top_num.' ';
89         } else {
90                 $top_num = $content_row['ordering'];
91                 $page_title .= $top_num.' ';
92         }
93 }
94
95 $parent = 0;
96
97 foreach ($path as $i=>$page) {
98         // When login is a student, remove content folder from breadcrumb path as content folders are
99         // just toggles for students. Keep content folder in breadcrumb path for instructors as they
100         // can edit content folder title. 
101         if ((!isset($_current_user) || !$_current_user->isAuthor($_course_id)) && 
102             $contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER) {
103                 unset($path[$i]);
104                 continue;
105         }
106         
107         if ($contentManager->_menu_info[$page['content_id']]['content_type'] == CONTENT_TYPE_FOLDER)
108                 $content_url = 'home/editor/edit_content_folder.php?_cid='.$page['content_id'];
109         else
110                 $content_url = 'home/course/content.php?_cid='.$page['content_id'];
111                 
112         if (!$parent) {
113                 $_pages[$content_url]['title']    = $page['content_number'] . $page['title'];
114                 $_pages[$content_url]['parent']   = 'home/index.php';
115         } else {
116                 $_pages[$content_url]['title']    = $page['content_number'] . $page['title'];
117                 if (isset($_pages['home/editor/edit_content_folder.php?_cid='.$parent])) {
118                         $_pages[$content_url]['parent']   = 'home/editor/edit_content_folder.php?_cid='.$parent;
119                 } else {
120                         $_pages[$content_url]['parent']   = 'home/course/content.php?_cid='.$parent;
121                 }
122         }
123
124         $_pages[$content_url]['ignore'] = true;
125         $parent = $page['content_id'];
126 }
127
128 $last_page = array_pop($_pages);
129 $_pages['home/course/content.php'] = $last_page;
130
131 reset($path);
132 $first_page = current($path);
133
134 /* the tests associated with the content */
135 $content_test_ids = array();    //the html
136 $content_test_rows = $contentManager->getContentTestsAssoc($cid);
137 if (is_array($content_test_rows))
138 {
139         foreach ($content_test_rows as $content_test_row){
140                 $content_test_ids[] = $content_test_row;
141         }
142 }
143
144 /* the forums associated with the content */
145 $contentForumsAssocDAO = new ContentForumsAssocDAO();
146 $content_forum_ids = $contentForumsAssocDAO->getByContent($cid);
147 //$content_test_rows = $contentManager->getContentTestsAssoc($cid);
148 //if (is_array($content_test_rows))
149 //{
150 //      foreach ($content_test_rows as $content_test_row){
151 //              $content_test_ids[] = $content_test_row;
152 //      }
153 //}
154
155 /*TODO***************BOLOGNA***************REMOVE ME**********/
156 /* the content forums extension page*/
157 //$content_forum_ids = array(); //the html
158 //$content_forum_rows = $contentManager->getContentForumsAssoc($cid);
159 //if (is_array($content_forum_rows))
160 //{
161 //      foreach ($content_forum_rows as $content_forum_row){
162 //              $content_forum_ids[] = $content_forum_row;
163 //      }
164 //}
165
166 // use any styles that were part of the imported document
167 // $_custom_css = $_base_href.'headstuff.php?cid='.$cid.SEP.'path='.urlEncode($_base_href.$course_base_href.$content_base_href);
168
169 if ($content_row['use_customized_head'] && strlen($content_row['head']) > 0)
170 {
171         $_custom_head .= $content_row['head'];
172 }
173
174 global $_custom_head;
175 $_custom_head .= '
176         <script language="javascript" type="text/javascript">
177         //<!--
178         jQuery(function() {
179         jQuery(\'a.tooltip\').tooltip( { showBody: ": ", showURL: false } );
180         } );
181         //-->
182         </script>
183 ';
184
185 if (isset($_SESSION['user_id'])) ContentUtility::saveLastCid($cid);
186
187 if (isset($top_num) && $top_num != (int) $top_num) {
188         $top_num = substr($top_num, 0, strpos($top_num, '.'));
189 }
190
191 $_tool_shortcuts = ContentUtility::getToolShortcuts($content_row);
192
193 //if it has test and forum associated with it, still display it even if the content is empty
194 if ($content_row['text'] == '' && empty($content_test_ids)){
195         $msg->addInfo('NO_PAGE_CONTENT');
196         $savant->assign('body', '');
197 } else {
198     // find whether the body has alternatives defined
199         list($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative)
200         = ContentUtility::applyAlternatives($cid, $content_row['text'], true);
201
202         // apply alternatives
203         if (intval($_GET['alternative']) > 0) {
204                 $content = ContentUtility::applyAlternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
205         } else {
206                 $content = ContentUtility::applyAlternatives($cid, $content_row['text']);
207         }
208
209     $content = ContentUtility::formatContent($content, $content_row['formatting']);
210
211         $content_array = ContentUtility::getContentTable($content, $content_row['formatting']);
212         
213         $savant->assign('content_table', $content_array[0]);
214         $savant->assign('body', $content_array[1]);
215         $savant->assign('has_text_alternative', $has_text_alternative);
216         $savant->assign('has_audio_alternative', $has_audio_alternative);
217         $savant->assign('has_visual_alternative', $has_visual_alternative);
218         $savant->assign('has_sign_lang_alternative', $has_sign_lang_alternative);
219         $savant->assign('cid', $cid);
220         
221         //assign test pages if there are tests associated with this content page
222         if (!empty($content_test_ids)){
223                 $savant->assign('test_message', $content_row['test_message']);
224                 $savant->assign('test_ids', $content_test_ids);
225         } else {
226                 $savant->assign('test_message', '');
227                 $savant->assign('test_ids', array());
228         }
229         
230         if (is_array($content_forum_ids)){
231                 $savant->assign('forum_ids', $content_forum_ids);
232         }
233 }
234
235 $savant->assign('content_info', _AT('page_info', AT_date(_AT('page_info_date_format'), $content_row['last_modified'], TR_DATE_MYSQL_DATETIME), $content_row['revision'], AT_date(_AT('inbox_date_format'), $content_row['release_date'], TR_DATE_MYSQL_DATETIME)));
236 $savant->assign('course_id', $_course_id);
237
238 require(TR_INCLUDE_PATH.'header.inc.php');
239
240 $savant->display('home/course/content.tmpl.php');
241
242 //save last visit page.
243 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
244
245 require (TR_INCLUDE_PATH.'footer.inc.php');
246 ?>