9b9886ae3c174bfcb32da5c289ebd83106987d9e
[moodle.git] / course / format / weeks / format.php
1 <?php
2       // Display the whole course as "weeks" made of of modules
3       // Included from "view.php"
4 /**
5  * Evaluation weekly format for course display - NO layout tables, for accessibility, etc.
6  *
7  * A duplicate course format to enable the Moodle development team to evaluate
8  * CSS for the multi-column layout in place of layout tables.
9  * Less risk for the Moodle 1.6 beta release.
10  *   1. Straight copy of weeks/format.php
11  *   2. Replace <table> and <td> with DIVs; inline styles.
12  *   3. Reorder columns so that in linear view content is first then blocks;
13  * styles to maintain original graphical (side by side) view.
14  *
15  * Target: 3-column graphical view using relative widths for pixel screen sizes
16  * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
17  *
18  * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
19  * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
20  *
21  * @copyright &copy; 2006 The Open University
22  * @author N.D.Freear@open.ac.uk, and others.
23  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
24  * @package
25  */
27 defined('MOODLE_INTERNAL') || die();
29     require_once($CFG->libdir.'/filelib.php');
30     require_once($CFG->libdir.'/completionlib.php');
32     $week = optional_param('week', -1, PARAM_INT);
34     if ($week != -1) {
35         $displaysection = course_set_display($course->id, $week);
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     $streditsummary  = get_string('editsummary');
45     $stradd          = get_string('add');
46     $stractivities   = get_string('activities');
47     $strshowallweeks = get_string('showallweeks');
48     $strweek         = get_string('week');
49     $strgroups       = get_string('groups');
50     $strgroupmy      = get_string('groupmy');
51     $editing         = $PAGE->user_is_editing();
53     if ($editing) {
54         $strweekhide = get_string('hideweekfromothers');
55         $strweekshow = get_string('showweekfromothers');
56         $strmoveup   = get_string('moveup');
57         $strmovedown = get_string('movedown');
58     }
60     $context = get_context_instance(CONTEXT_COURSE, $course->id);
62     //Print the Your progress icon if the track completion is enabled
63     $completioninfo = new completion_info($course);
64     $completioninfo->print_help_icon();
66     echo $OUTPUT->heading(get_string('weeklyoutline'), 2, 'headingblock header outline');
68     echo "<span id='maincontent'></span>";
69     // Note, an ordered list would confuse - "1" could be the clipboard or summary.
70     echo "<ul class='weeks'>\n";
72 /// If currently moving a file then show the current clipboard
73     if (ismoving($course->id)) {
74         $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
75         $strcancel= get_string('cancel');
76         echo '<li class="clipboard">';
77         echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
78         echo "</li>\n";
79     }
81 /// Print Section 0 with general activities
83     $section = 0;
84     $thissection = $sections[$section];
85     unset($sections[0]);
87     if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
89         // Note, 'right side' is BEFORE content.
90         echo '<li id="section-0" class="section main clearfix" >';
91         echo '<div class="left side">&nbsp;</div>';
92         echo '<div class="right side" >&nbsp;</div>';
93         echo '<div class="content">';
95         if (!empty($thissection->name)) {
96             echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
97         }
99         echo '<div class="summary">';
101         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
102         $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
103         $summaryformatoptions = new stdClass;
104         $summaryformatoptions->noclean = true;
105         $summaryformatoptions->overflowdiv = true;
106         echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
108         if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
109             echo '<p><a title="'.$streditsummary.'" '.
110                  ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
111                  ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
112         }
113         echo '</div>';
115         print_section($course, $thissection, $mods, $modnamesused);
117         if ($PAGE->user_is_editing()) {
118             print_section_add_menus($course, $section, $modnames);
119         }
121         echo '</div>';
122         echo "</li>\n";
123     }
126 /// Now all the normal modules by week
127 /// Everything below uses "section" terminology - each "section" is a week.
129     $timenow = time();
130     $weekdate = $course->startdate;    // this should be 0:00 Monday of that week
131     $weekdate += 7200;                 // Add two hours to avoid possible DST problems
132     $section = 1;
133     $sectionmenu = array();
134     $weekofseconds = 604800;
135     $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
137     $strftimedateshort = ' '.get_string('strftimedateshort');
139     while ($weekdate < $course->enddate) {
141         $nextweekdate = $weekdate + ($weekofseconds);
142         $weekday = userdate($weekdate, $strftimedateshort);
143         $endweekday = userdate($weekdate+518400, $strftimedateshort);
145         if (!empty($sections[$section])) {
146             $thissection = $sections[$section];
148         } else {
149             unset($thissection);
150             $thissection->course = $course->id;   // Create a new week structure
151             $thissection->section = $section;
152             $thissection->name    = null;
153             $thissection->summary = '';
154             $thissection->summaryformat = FORMAT_HTML;
155             $thissection->visible = 1;
156             $thissection->id = $DB->insert_record('course_sections', $thissection);
157         }
159         $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
161         if (!empty($displaysection) and $displaysection != $section) {  // Check this week is visible
162             if ($showsection) {
163                 $sectionmenu[$section] = get_section_name($course, $thissection);
164             }
165             $section++;
166             $weekdate = $nextweekdate;
167             continue;
168         }
170         if ($showsection) {
172             $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
174             $currenttext = '';
175             if (!$thissection->visible) {
176                 $sectionstyle = ' hidden';
177             } else if ($currentweek) {
178                 $sectionstyle = ' current';
179                 $currenttext = get_accesshide(get_string('currentweek','access'));
180             } else {
181                 $sectionstyle = '';
182             }
184             echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >';
186             echo '<div class="left side">&nbsp;'.$currenttext.'</div>';
188             // Note, 'right side' is BEFORE content.
189             echo '<div class="right side">';
191             if ($displaysection == $section) {
192                 echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
193                      '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
194             } else {
195                 $strshowonlyweek = get_string("showonlyweek", "", $section);
196                 echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
197                      '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
198             }
200             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
201                 if ($thissection->visible) {        // Show the hide/show eye
202                     echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
203                          '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
204                 } else {
205                     echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekshow.'">'.
206                          '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
207                 }
208                 if ($section > 1) {                       // Add a arrow to move section up
209                     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.'">'.
210                          '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
211                 }
213                 if ($section < $course->numsections) {    // Add a arrow to move section down
214                     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.'">'.
215                          '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
216                 }
217             }
218             echo '</div>';
220             $weekperiod = $weekday.' - '.$endweekday;
222             echo '<div class="content">';
223             if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
224                 echo $OUTPUT->heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', 3, 'weekdates');
226             } else {
227                 if (isset($thissection->name) && ($thissection->name !== NULL)) {  // empty string is ok
228                     echo $OUTPUT->heading($thissection->name, 3, 'weekdates');
229                 } else {
230                     echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates');
231                 }
232                 echo '<div class="summary">';
233                 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
234                 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
235                 $summaryformatoptions = new stdClass;
236                 $summaryformatoptions->noclean = true;
237                 $summaryformatoptions->overflowdiv = true;
238                 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
240                 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
241                     echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
242                          '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
243                 }
244                 echo '</div>';
246                 print_section($course, $thissection, $mods, $modnamesused);
248                 if ($PAGE->user_is_editing()) {
249                     print_section_add_menus($course, $section, $modnames);
250                 }
251             }
253             echo '</div>';
254             echo "</li>\n";
255         }
257         unset($sections[$section]);
258         $section++;
259         $weekdate = $nextweekdate;
260     }
262     if (!$displaysection and $PAGE->user_is_editing() and has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
263         // print stealth sections if present
264         $modinfo = get_fast_modinfo($course);
265         foreach ($sections as $section=>$thissection) {
266             if (empty($modinfo->sections[$section])) {
267                 continue;
268             }
270             echo '<li id="section-'.$section.'" class="section main clearfix stealth hidden">'; //'<div class="left side">&nbsp;</div>';
272             echo '<div class="left side">';
273             echo '</div>';
274             // Note, 'right side' is BEFORE content.
275             echo '<div class="right side">';
276             echo '</div>';
277             echo '<div class="content">';
278             echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
279             print_section($course, $thissection, $mods, $modnamesused);
280             echo '</div>';
281             echo "</li>\n";
282         }
283     }
285     echo "</ul>\n";
287     if (!empty($sectionmenu)) {
288         $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'week', $sectionmenu);
289         $select->label = get_string('jumpto');
290         $select->class = 'jumpmenu';
291         $select->formid = 'sectionmenu';
292         echo $OUTPUT->render($select);
293     }