made a copy
[atutor.git] / content.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
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 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 foreach ($path as $page) {
91         if (!$parent) {
92                 $_pages['content.php?cid='.$page['content_id']]['title']    = $page['content_number'] . $page['title'];
93                 $_pages['content.php?cid='.$page['content_id']]['parent']   = 'index.php';
94         } else {
95                 $_pages['content.php?cid='.$page['content_id']]['title']    = $page['content_number'] . $page['title'];
96                 $_pages['content.php?cid='.$page['content_id']]['parent']   = 'content.php?cid='.$parent;
97         }
98
99         $_pages['content.php?cid='.$page['content_id']]['ignore'] = true;
100         $parent = $page['content_id'];
101 }
102 $last_page = array_pop($_pages);
103 $_pages['content.php'] = $last_page;
104
105 reset($path);
106 $first_page = current($path);
107
108 /* the content test extension page */
109 $content_test_ids = array();    //the html
110 $content_test_rs = $contentManager->getContentTestsAssoc($cid);
111 while ($content_test_row = mysql_fetch_assoc($content_test_rs)){
112         $content_test_ids[] = $content_test_row;
113 }
114
115 // use any styles that were part of the imported document
116 // $_custom_css = $_base_href.'headstuff.php?cid='.$cid.SEP.'path='.urlEncode($_base_href.$course_base_href.$content_base_href);
117
118 if ($content_row['use_customized_head'] && strlen($content_row['head']) > 0)
119 {
120         $_custom_head = $content_row['head'];
121 }
122
123 global $_custom_head;
124 $_custom_head = '
125         <script language="javascript" type="text/javascript">
126         //<!--
127         $(function() {
128         $(\'a.tooltip\').tooltip( { showBody: ": ", showURL: false } );
129         } );
130         //-->
131         </script>
132 ';
133
134 require(AT_INCLUDE_PATH.'header.inc.php');
135
136 save_last_cid($cid);
137 if (isset($top_num) && $top_num != (int) $top_num) {
138         $top_num = substr($top_num, 0, strpos($top_num, '.'));
139 }
140
141 $shortcuts = array();
142 if ((   ($content_row['r_date'] <= $content_row['n_date'])
143                 && ((!$content_row['content_parent_id'] && ($_SESSION['packaging'] == 'top'))
144                         || ($_SESSION['packaging'] == 'all'))
145         ) || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
146
147         $shortcuts[] = array('title' => _AT('export_content'), 'url' => $_base_href . 'tools/ims/ims_export.php?cid='.$cid);
148 }
149
150 if (authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
151         $shortcuts[] = array('title' => _AT('edit_this_page'),   'url' => $_base_href . 'editor/edit_content.php?cid='.$cid);
152         $shortcuts[] = array('title' => _AT('add_top_page'),     'url' => $_base_href . 'editor/edit_content.php');
153         if ($contentManager->_menu_info[$cid]['content_parent_id']) {
154                 $shortcuts[] = array('title' => _AT('add_sibling_page'), 'url' => $_base_href .
155                         'editor/edit_content.php?pid='.$contentManager->_menu_info[$cid]['content_parent_id']);
156         }
157         $shortcuts[] = array('title' => _AT('add_sub_page'),     'url' => $_base_href . 'editor/edit_content.php?pid='.$cid);
158         $shortcuts[] = array('title' => _AT('delete_this_page'), 'url' => $_base_href . 'editor/delete_content.php?cid='.$cid);
159 }
160 $savant->assign('shortcuts', $shortcuts);
161
162 /* if i'm an admin then let me see content, otherwise only if released */
163 $released_status = $contentManager->isReleased($cid);
164 if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
165         if ($content_row['text'] == '') {
166                 $msg->addInfo('NO_PAGE_CONTENT');
167                 $msg->printAll();
168                 $savant->assign('body', '');
169         } else {
170                 if ($released_status !== TRUE) {
171                         /* show the instructor that this content hasn't been released yet */
172                         $infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
173                         $msg->addInfo($infos);
174                         $msg->printAll();
175                         unset($infos);
176                 }
177
178                 /* @See: include/lib/output.inc.php */
179                 
180                 //Silvia: to provide appropriated content on the basis of users' preferences
181
182                 $content = provide_alternatives($cid, $content_row['text']);
183                 $content = format_content($content, $content_row['formatting'], $glossary);
184
185                 $content_array = get_content_table($content);
186                 
187                 $savant->assign('content_table', $content_array[0]);
188                 $savant->assign('body', $content_array[1]);
189
190                 //assign test pages if there are tests associated with this content page
191                 if (!empty($content_test_ids)){
192                         $savant->assign('test_message', $content_row['test_message']);
193                         $savant->assign('test_ids', $content_test_ids);
194                 } else {
195                         $savant->assign('test_message', '');
196                         $savant->assign('test_ids', array());
197                 }
198                                         
199                                 
200         }
201 } else {
202         $infos = array('NOT_RELEASED', AT_date(_AT('announcement_date_format'), $released_status, AT_DATE_UNIX_TIMESTAMP));
203         $msg->addInfo($infos);
204         $msg->printAll();
205         unset($infos);
206 }
207
208 $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)));
209
210 $savant->display('content.tmpl.php');
211
212 //save last visit page.
213 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
214
215 require (AT_INCLUDE_PATH.'footer.inc.php');
216 ?>