fc0d138da22d21f15b483bdcbb76b3bfb1d41bc8
[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');
31 require_once($CFG->libdir.'/completionlib.php');
33 $topic = optional_param('topic', -1, PARAM_INT);
35 if ($topic != -1) {
36     $displaysection = course_set_display($course->id, $topic);
37 } else {
38     $displaysection = course_get_display($course->id);
39 }
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     course_set_marker($course->id, $marker);
46 }
48 $streditsummary  = get_string('editsummary');
49 $stradd          = get_string('add');
50 $stractivities   = get_string('activities');
51 $strshowalltopics = get_string('showalltopics');
52 $strtopic         = get_string('topic');
53 $strgroups       = get_string('groups');
54 $strgroupmy      = get_string('groupmy');
55 $editing         = $PAGE->user_is_editing();
57 if ($editing) {
58     $strtopichide = get_string('hidefromothers', 'format_topics');
59     $strtopicshow = get_string('showfromothers', 'format_topics');
60     $strmarkthistopic = get_string('markthistopic');
61     $strmarkedthistopic = get_string('markedthistopic');
62     $strmoveup   = get_string('moveup');
63     $strmovedown = get_string('movedown');
64 }
66 // Print the Your progress icon if the track completion is enabled
67 $completioninfo = new completion_info($course);
68 echo $completioninfo->display_help_icon();
70 echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
72 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
73 echo "<ul class='topics'>\n";
75 /// If currently moving a file then show the current clipboard
76 if (ismoving($course->id)) {
77     $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
78     $strcancel= get_string('cancel');
79     echo '<li class="clipboard">';
80     echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
81     echo "</li>\n";
82 }
84 /// Print Section 0 with general activities
86 $section = 0;
87 $thissection = $sections[$section];
88 unset($sections[0]);
90 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
92     // Note, no need for a 'left side' cell or DIV.
93     // Note, 'right side' is BEFORE content.
94     echo '<li id="section-0" class="section main clearfix" >';
95     echo '<div class="left side">&nbsp;</div>';
96     echo '<div class="right side" >&nbsp;</div>';
97     echo '<div class="content">';
98     if (!is_null($thissection->name)) {
99         echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
100     }
101     echo '<div class="summary">';
103     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
104     $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
105     $summaryformatoptions = new stdClass();
106     $summaryformatoptions->noclean = true;
107     $summaryformatoptions->overflowdiv = true;
108     echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
110     if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
111         echo '<a title="'.$streditsummary.'" '.
112              ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
113              ' class="iconsmall edit" alt="'.$streditsummary.'" /></a>';
114     }
115     echo '</div>';
117     print_section($course, $thissection, $mods, $modnamesused);
119     if ($PAGE->user_is_editing()) {
120         print_section_add_menus($course, $section, $modnames);
121     }
123     echo '</div>';
124     echo "</li>\n";
128 /// Now all the normal modules by topic
129 /// Everything below uses "section" terminology - each "section" is a topic.
131 $section = 1;
132 $sectionmenu = array();
134 while ($section <= $course->numsections) {
136     if (!empty($sections[$section])) {
137         $thissection = $sections[$section];
139     } else {
140         $thissection = new stdClass;
141         $thissection->course  = $course->id;   // Create a new section structure
142         $thissection->section = $section;
143         $thissection->name    = null;
144         $thissection->summary  = '';
145         $thissection->summaryformat = FORMAT_HTML;
146         $thissection->visible  = 1;
147         $thissection->id = $DB->insert_record('course_sections', $thissection);
148     }
150     $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
152     if (!empty($displaysection) and $displaysection != $section) {  // Check this topic is visible
153         if ($showsection) {
154             $sectionmenu[$section] = get_section_name($course, $thissection);
155         }
156         $section++;
157         continue;
158     }
160     if ($showsection) {
162         $currenttopic = ($course->marker == $section);
164         $currenttext = '';
165         if (!$thissection->visible) {
166             $sectionstyle = ' hidden';
167         } else if ($currenttopic) {
168             $sectionstyle = ' current';
169             $currenttext = get_accesshide(get_string('currenttopic','access'));
170         } else {
171             $sectionstyle = '';
172         }
174         echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
176             echo '<div class="left side">'.$currenttext.$section.'</div>';
177         // Note, 'right side' is BEFORE content.
178         echo '<div class="right side">';
180         if ($displaysection == $section) {    // Show the zoom boxes
181             echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
182                  '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
183         } else {
184             $strshowonlytopic = get_string("showonlytopic", "", $section);
185             echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
186                  '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
187         }
189         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
191             if ($course->marker == $section) {  // Show the "light globe" on/off
192                 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'" class="editing_highlight">'.'<img src="'.$OUTPUT->pix_url('i/marked') . '" alt="'.$strmarkedthistopic.'" class="icon"/></a><br />';
193             } else {
194                 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'" class="editing_highlight">'.'<img src="'.$OUTPUT->pix_url('i/marker') . '" alt="'.$strmarkthistopic.'" class="icon"/></a><br />';
195             }
197             if ($thissection->visible) {        // Show the hide/show eye
198                 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'" class="editing_showhide">'.
199                      '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
200             } else {
201                 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'" class="editing_showhide">'.
202                      '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
203             }
204             if ($section > 1) {                       // Add a arrow to move section up
205                 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.'" class="moveup">'.
206                      '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
207             }
209             if ($section < $course->numsections) {    // Add a arrow to move section down
210                 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.'" class="movedown">'.
211                      '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
212             }
213         }
214         echo '</div>';
216         echo '<div class="content">';
217         if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
218             echo get_string('notavailable');
219         } else {
220             if (!is_null($thissection->name)) {
221                 echo $OUTPUT->heading(format_string($thissection->name, true, array('context' => $context)), 3, 'sectionname');
222             }
223             echo '<div class="summary">';
224             if ($thissection->summary) {
225                 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
226                 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
227                 $summaryformatoptions = new stdClass();
228                 $summaryformatoptions->noclean = true;
229                 $summaryformatoptions->overflowdiv = true;
230                 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
231             } else {
232                echo '&nbsp;';
233             }
235             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
236                 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
237                      '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
238             }
239             echo '</div>';
241             print_section($course, $thissection, $mods, $modnamesused);
242             echo '<br />';
243             if ($PAGE->user_is_editing()) {
244                 print_section_add_menus($course, $section, $modnames);
245             }
246         }
248         echo '</div>';
249         echo "</li>\n";
250     }
252     unset($sections[$section]);
253     $section++;
256 if (!$displaysection and $PAGE->user_is_editing() and has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
257     // print stealth sections if present
258     $modinfo = get_fast_modinfo($course);
259     foreach ($sections as $section=>$thissection) {
260         if (empty($modinfo->sections[$section])) {
261             continue;
262         }
264         echo '<li id="section-'.$section.'" class="section main clearfix orphaned hidden">'; //'<div class="left side">&nbsp;</div>';
266         echo '<div class="left side">';
267         echo '</div>';
268         // Note, 'right side' is BEFORE content.
269         echo '<div class="right side">';
270         echo '</div>';
271         echo '<div class="content">';
272         echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
273         print_section($course, $thissection, $mods, $modnamesused);
274         echo '</div>';
275         echo "</li>\n";
276     }
280 echo "</ul>\n";
282 if (!empty($sectionmenu)) {
283     $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);
284     $select->label = get_string('jumpto');
285     $select->class = 'jumpmenu';
286     $select->formid = 'sectionmenu';
287     echo $OUTPUT->render($select);
290     // Include course format js module
291     $PAGE->requires->js('/course/format/topics/format.js');