Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / format / topics / format.php
blob0a0b59adef4aebc56194448aa04323d9794a30f5
1 <?php // $Id$
2 // Display the whole course as "topics" made of of modules
3 // In fact, this is very similar to the "weeks" format, in that
4 // each "topic" is actually a week. The main difference is that
5 // the dates aren't printed - it's just an aesthetic thing for
6 // courses that aren't so rigidly defined by time.
7 // Included from "view.php"
10 require_once($CFG->libdir.'/ajax/ajaxlib.php');
12 $topic = optional_param('topic', -1, PARAM_INT);
14 // Bounds for block widths
15 // more flexible for theme designers taken from theme config.php
16 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
17 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
18 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
19 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
21 define('BLOCK_L_MIN_WIDTH', $lmin);
22 define('BLOCK_L_MAX_WIDTH', $lmax);
23 define('BLOCK_R_MIN_WIDTH', $rmin);
24 define('BLOCK_R_MAX_WIDTH', $rmax);
26 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
27 BLOCK_L_MAX_WIDTH);
28 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
29 BLOCK_R_MAX_WIDTH);
31 if ($topic != -1) {
32 $displaysection = course_set_display($course->id, $topic);
33 } else {
34 if (isset($USER->display[$course->id])) { // for admins, mostly
35 $displaysection = $USER->display[$course->id];
36 } else {
37 $displaysection = course_set_display($course->id, 0);
41 $context = get_context_instance(CONTEXT_COURSE, $course->id);
43 if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
44 $course->marker = $marker;
45 if (! set_field("course", "marker", $marker, "id", $course->id)) {
46 error("Could not mark that topic for this course");
50 $streditsummary = get_string('editsummary');
51 $stradd = get_string('add');
52 $stractivities = get_string('activities');
53 $strshowalltopics = get_string('showalltopics');
54 $strtopic = get_string('topic');
55 $strgroups = get_string('groups');
56 $strgroupmy = get_string('groupmy');
57 $editing = $PAGE->user_is_editing();
59 if ($editing) {
60 $strstudents = moodle_strtolower($course->students);
61 $strtopichide = get_string('topichide', '', $strstudents);
62 $strtopicshow = get_string('topicshow', '', $strstudents);
63 $strmarkthistopic = get_string('markthistopic');
64 $strmarkedthistopic = get_string('markedthistopic');
65 $strmoveup = get_string('moveup');
66 $strmovedown = get_string('movedown');
70 /// Layout the whole page as three big columns.
71 echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'"><tr>';
73 /// The left column ...
74 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
75 foreach ($lt as $column) {
76 switch ($column) {
77 case 'left':
79 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
80 echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
81 print_container_start();
82 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
83 print_container_end();
84 echo '</td>';
87 break;
88 case 'middle':
89 /// Start main column
90 echo '<td id="middle-column">';
91 print_container_start();
92 echo skip_main_destination();
94 print_heading_block(get_string('topicoutline'), 'outline');
96 echo '<table class="topics" width="100%" summary="'.get_string('layouttable').'">';
98 /// If currently moving a file then show the current clipboard
99 if (ismoving($course->id)) {
100 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
101 $strcancel= get_string('cancel');
102 echo '<tr class="clipboard">';
103 echo '<td colspan="3">';
104 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
105 echo '</td>';
106 echo '</tr>';
109 /// Print Section 0
111 $section = 0;
112 $thissection = $sections[$section];
114 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
115 echo '<tr id="section-0" class="section main">';
116 echo '<td class="left side">&nbsp;</td>';
117 echo '<td class="content">';
119 echo '<div class="summary">';
120 $summaryformatoptions->noclean = true;
121 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
123 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
124 echo '<a title="'.$streditsummary.'" '.
125 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
126 ' alt="'.$streditsummary.'" /></a><br /><br />';
128 echo '</div>';
130 print_section($course, $thissection, $mods, $modnamesused);
132 if (isediting($course->id)) {
133 print_section_add_menus($course, $section, $modnames);
136 echo '</td>';
137 echo '<td class="right side">&nbsp;</td>';
138 echo '</tr>';
139 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
143 /// Now all the normal modules by topic
144 /// Everything below uses "section" terminology - each "section" is a topic.
146 $timenow = time();
147 $section = 1;
148 $sectionmenu = array();
150 while ($section <= $course->numsections) {
152 if (!empty($sections[$section])) {
153 $thissection = $sections[$section];
155 } else {
156 unset($thissection);
157 $thissection->course = $course->id; // Create a new section structure
158 $thissection->section = $section;
159 $thissection->summary = '';
160 $thissection->visible = 1;
161 if (!$thissection->id = insert_record('course_sections', $thissection)) {
162 notify('Error inserting new topic!');
166 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
168 if (!empty($displaysection) and $displaysection != $section) {
169 if ($showsection) {
170 $strsummary = strip_tags(format_string($thissection->summary,true));
171 if (strlen($strsummary) < 57) {
172 $strsummary = ' - '.$strsummary;
173 } else {
174 $strsummary = ' - '.substr($strsummary, 0, 60).'...';
176 $sectionmenu['topic='.$section] = s($section.$strsummary);
178 $section++;
179 continue;
182 if ($showsection) {
184 $currenttopic = ($course->marker == $section);
186 $currenttext = '';
187 if (!$thissection->visible) {
188 $sectionstyle = ' hidden';
189 } else if ($currenttopic) {
190 $sectionstyle = ' current';
191 $currenttext = get_accesshide(get_string('currenttopic','access'));
192 } else {
193 $sectionstyle = '';
196 echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
197 echo '<td class="left side">'.$currenttext.$section.'</td>';
199 echo '<td class="content">';
200 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
201 echo get_string('notavailable');
202 } else {
203 echo '<div class="summary">';
204 $summaryformatoptions->noclean = true;
205 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
207 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
208 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
209 '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$streditsummary.'" /></a><br /><br />';
211 echo '</div>';
213 print_section($course, $thissection, $mods, $modnamesused);
215 if (isediting($course->id)) {
216 print_section_add_menus($course, $section, $modnames);
219 echo '</td>';
221 echo '<td class="right side">';
222 if ($displaysection == $section) { // Show the zoom boxes
223 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
224 '<img src="'.$CFG->pixpath.'/i/all.gif" alt="'.$strshowalltopics.'" /></a><br />';
225 } else {
226 $strshowonlytopic = get_string('showonlytopic', '', $section);
227 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
228 '<img src="'.$CFG->pixpath.'/i/one.gif" alt="'.$strshowonlytopic.'" /></a><br />';
231 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
232 if ($course->marker == $section) { // Show the "light globe" on/off
233 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
234 '<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
235 } else {
236 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkthistopic.'">'.
237 '<img src="'.$CFG->pixpath.'/i/marker.gif" alt="'.$strmarkthistopic.'" /></a><br />';
240 if ($thissection->visible) { // Show the hide/show eye
241 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopichide.'">'.
242 '<img src="'.$CFG->pixpath.'/i/hide.gif" alt="'.$strtopichide.'" /></a><br />';
243 } else {
244 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopicshow.'">'.
245 '<img src="'.$CFG->pixpath.'/i/show.gif" alt="'.$strtopicshow.'" /></a><br />';
248 if ($section > 1) { // Add a arrow to move section up
249 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
250 '<img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" /></a><br />';
253 if ($section < $course->numsections) { // Add a arrow to move section down
254 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
255 '<img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" /></a><br />';
260 echo '</td></tr>';
261 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
264 $section++;
266 echo '</table>';
268 if (!empty($sectionmenu)) {
269 echo '<div align="center" class="jumpmenu">';
270 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
271 'sectionmenu', '', get_string('jumpto'), '', '', true);
272 echo '</div>';
275 print_container_end();
276 echo '</td>';
278 break;
279 case 'right':
280 // The right column
281 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
282 echo '<td style="width:'.$preferred_width_right.'px" id="right-column">';
283 print_container_start();
284 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
285 print_container_end();
286 echo '</td>';
289 break;
292 echo '</tr></table>';