course-format-topic MDL-24680 Fixed XHTML bug that was destroying page layout.
[moodle.git] / course / format / topics / format.php
1 <?php
3 // Display the whole course as "topics" made of of modules
4 // Included from "view.php"
5 /**
6  * Evaluation topics format for course display - NO layout tables, for accessibility, etc.
7  *
8  * A duplicate course format to enable the Moodle development team to evaluate
9  * CSS for the multi-column layout in place of layout tables.
10  * Less risk for the Moodle 1.6 beta release.
11  *   1. Straight copy of topics/format.php
12  *   2. Replace <table> and <td> with DIVs; inline styles.
13  *   3. Reorder columns so that in linear view content is first then blocks;
14  * styles to maintain original graphical (side by side) view.
15  *
16  * Target: 3-column graphical view using relative widths for pixel screen sizes
17  * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
18  *
19  * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
20  * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
21  *
22  * @copyright &copy; 2006 The Open University
23  * @author N.D.Freear@open.ac.uk, and others.
24  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25  * @package
26  */
28 defined('MOODLE_INTERNAL') || die();
30 require_once($CFG->libdir.'/filelib.php');
32 $topic = optional_param('topic', -1, PARAM_INT);
34 if ($topic != -1) {
35     $displaysection = course_set_display($course->id, $topic);
36 } else {
37     if (isset($USER->display[$course->id])) {
38         $displaysection = $USER->display[$course->id];
39     } else {
40         $displaysection = course_set_display($course->id, 0);
41     }
42 }
44 $context = get_context_instance(CONTEXT_COURSE, $course->id);
46 if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
47     $course->marker = $marker;
48     $DB->set_field("course", "marker", $marker, array("id"=>$course->id));
49 }
51 $streditsummary  = get_string('editsummary');
52 $stradd          = get_string('add');
53 $stractivities   = get_string('activities');
54 $strshowalltopics = get_string('showalltopics');
55 $strtopic         = get_string('topic');
56 $strgroups       = get_string('groups');
57 $strgroupmy      = get_string('groupmy');
58 $editing         = $PAGE->user_is_editing();
60 if ($editing) {
61     $strtopichide = get_string('hidetopicfromothers');
62     $strtopicshow = get_string('showtopicfromothers');
63     $strmarkthistopic = get_string('markthistopic');
64     $strmarkedthistopic = get_string('markedthistopic');
65     $strmoveup   = get_string('moveup');
66     $strmovedown = get_string('movedown');
67 }
69 // Print the Your progress icon if the track completion is enabled
70 $completioninfo = new completion_info($course);
71 $completioninfo->print_help_icon();
73 echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
75 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
76 echo "<ul class='topics'>\n";
78 /// If currently moving a file then show the current clipboard
79 if (ismoving($course->id)) {
80     $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
81     $strcancel= get_string('cancel');
82     echo '<li class="clipboard">';
83     echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
84     echo "</li>\n";
85 }
87 /// Print Section 0 with general activities
89 $section = 0;
90 $thissection = $sections[$section];
91 unset($sections[0]);
93 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
95     // Note, no need for a 'left side' cell or DIV.
96     // Note, 'right side' is BEFORE content.
97     echo '<li id="section-0" class="section main clearfix" >';
98     echo '<div class="left side">&nbsp;</div>';
99     echo '<div class="right side" >&nbsp;</div>';
100     echo '<div class="content">';
101     if (!is_null($thissection->name)) {
102         echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
103     }
104     echo '<div class="summary">';
106     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
107     $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
108     $summaryformatoptions = new stdClass();
109     $summaryformatoptions->noclean = true;
110     echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
112     if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
113         echo '<a title="'.$streditsummary.'" '.
114              ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
115              ' class="icon edit" alt="'.$streditsummary.'" /></a>';
116     }
117     echo '</div>';
119     print_section($course, $thissection, $mods, $modnamesused);
121     if ($PAGE->user_is_editing()) {
122         print_section_add_menus($course, $section, $modnames);
123     }
125     echo '</div>';
126     echo "</li>\n";
130 /// Now all the normal modules by topic
131 /// Everything below uses "section" terminology - each "section" is a topic.
133 $timenow = time();
134 $section = 1;
135 $sectionmenu = array();
137 while ($section <= $course->numsections) {
139     if (!empty($sections[$section])) {
140         $thissection = $sections[$section];
142     } else {
143         $thissection = new stdClass;
144         $thissection->course  = $course->id;   // Create a new section structure
145         $thissection->section = $section;
146         $thissection->name    = null;
147         $thissection->summary  = '';
148         $thissection->summaryformat = FORMAT_HTML;
149         $thissection->visible  = 1;
150         $thissection->id = $DB->insert_record('course_sections', $thissection);
151     }
153     $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
155     if (!empty($displaysection) and $displaysection != $section) {  // Check this topic is visible
156         if ($showsection) {
157             $sectionmenu[$section] = get_section_name($course, $thissection);
158         }
159         $section++;
160         continue;
161     }
163     if ($showsection) {
165         $currenttopic = ($course->marker == $section);
167         $currenttext = '';
168         if (!$thissection->visible) {
169             $sectionstyle = ' hidden';
170         } else if ($currenttopic) {
171             $sectionstyle = ' current';
172             $currenttext = get_accesshide(get_string('currenttopic','access'));
173         } else {
174             $sectionstyle = '';
175         }
177         echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
179             echo '<div class="left side">'.$currenttext.$section.'</div>';
180         // Note, 'right side' is BEFORE content.
181         echo '<div class="right side">';
183         if ($displaysection == $section) {    // Show the zoom boxes
184             echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
185                  '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
186         } else {
187             $strshowonlytopic = get_string("showonlytopic", "", $section);
188             echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
189                  '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
190         }
192         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
194             if ($course->marker == $section) {  // Show the "light globe" on/off
195                 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$OUTPUT->pix_url('i/marked') . '" alt="'.$strmarkedthistopic.'" /></a><br />';
196             } else {
197                 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'">'.'<img src="'.$OUTPUT->pix_url('i/marker') . '" alt="'.$strmarkthistopic.'" /></a><br />';
198             }
200             if ($thissection->visible) {        // Show the hide/show eye
201                 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
202                      '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
203             } else {
204                 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
205                      '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
206             }
207             if ($section > 1) {                       // Add a arrow to move section up
208                 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
209                      '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
210             }
212             if ($section < $course->numsections) {    // Add a arrow to move section down
213                 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
214                      '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
215             }
216         }
217         echo '</div>';
219         echo '<div class="content">';
220         if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
221             echo get_string('notavailable');
222         } else {
223             if (!is_null($thissection->name)) {
224                 echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
225             }
226             echo '<div class="summary">';
227             if ($thissection->summary) {
228                 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
229                 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
230                 $summaryformatoptions = new stdClass();
231                 $summaryformatoptions->noclean = true;
232                 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
233             } else {
234                echo '&nbsp;';
235             }
237             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
238                 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
239                      '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
240             }
241             echo '</div>';
243             print_section($course, $thissection, $mods, $modnamesused);
244             echo '<br />';
245             if ($PAGE->user_is_editing()) {
246                 print_section_add_menus($course, $section, $modnames);
247             }
248         }
250         echo '</div>';
251         echo "</li>\n";
252     }
254     unset($sections[$section]);
255     $section++;
258 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
259     // print stealth sections if present
260     $modinfo = get_fast_modinfo($course);
261     foreach ($sections as $section=>$thissection) {
262         if (empty($modinfo->sections[$section])) {
263             continue;
264         }
266         echo '<li id="section-'.$section.'" class="section main clearfix orphaned hidden">'; //'<div class="left side">&nbsp;</div>';
268         echo '<div class="left side">';
269         echo '</div>';
270         // Note, 'right side' is BEFORE content.
271         echo '<div class="right side">';
272         echo '</div>';
273         echo '<div class="content">';
274         echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
275         print_section($course, $thissection, $mods, $modnamesused);
276         echo '</div>';
277         echo "</li>\n";
278     }
282 echo "</ul>\n";
284 if (!empty($sectionmenu)) {
285     $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);
286     $select->label = get_string('jumpto');
287     $select->class = 'jumpmenu';
288     $select->formid = 'sectionmenu';
289     echo $OUTPUT->render($select);