calendar/lib: calendar_set_filters() use pre-fetched context and course recs
[moodle-pu.git] / course / format / weekscss / format.php
blobfec9bc6e677279f22758c709bcc7692d96fc4177
1 <?php // $Id$
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.
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.
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.
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
26 //TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formatweekscss']
28 $week = optional_param('week', -1, PARAM_INT);
30 if ($week != -1) {
31 $displaysection = course_set_display($course->id, $week);
32 } else {
33 if (isset($USER->display[$course->id])) {
34 $displaysection = $USER->display[$course->id];
35 } else {
36 $displaysection = course_set_display($course->id, 0);
40 $streditsummary = get_string('editsummary');
41 $stradd = get_string('add');
42 $stractivities = get_string('activities');
43 $strshowallweeks = get_string('showallweeks');
44 $strweek = get_string('week');
45 $strgroups = get_string('groups');
46 $strgroupmy = get_string('groupmy');
47 $editing = $PAGE->user_is_editing();
49 if ($editing) {
50 $strstudents = moodle_strtolower($course->students);
51 $strweekhide = get_string('weekhide', '', $strstudents);
52 $strweekshow = get_string('weekshow', '', $strstudents);
53 $strmoveup = get_string('moveup');
54 $strmovedown = get_string('movedown');
57 $context = get_context_instance(CONTEXT_COURSE, $course->id);
58 /* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
59 Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)
63 <!--[if IE]>
64 <style type="text/css">
65 .weekscss-format { width: expression(document.body.clientWidth < 800 ? "752px" : "auto"); }
66 </style>
67 <![endif]-->
68 <?php
69 /// Layout the whole page as three big columns (was, id="layout-table")
70 echo '<div class="weekscss-format">';
72 /// The left column ...
74 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
75 echo '<div id="left-column">';
76 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
77 echo '</div>';
80 /// The right column, BEFORE the middle-column.
81 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
82 echo '<div id="right-column">';
83 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
84 echo '</div>';
87 /// Start main column
88 echo '<div id="middle-column"><a name="startofcontent"></a>';
90 print_heading_block(get_string('weeklyoutline'), 'outline');
92 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
93 echo "<ul class='weekscss'>\n";
95 /// If currently moving a file then show the current clipboard
96 if (ismoving($course->id)) {
97 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
98 $strcancel= get_string('cancel');
99 echo '<li class="clipboard">';
100 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
101 echo "</li>\n";
104 /// Print Section 0 with general activities
106 $section = 0;
107 $thissection = $sections[$section];
109 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
111 // Note, no need for a 'left side' cell or DIV.
112 // Note, 'right side' is BEFORE content.
113 echo '<li id="section-0" class="section main" >';
114 echo '<div class="right side" >&nbsp;</div>';
115 echo '<div class="content">';
117 echo '<div class="summary">';
118 $summaryformatoptions->noclean = true;
119 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
121 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
122 echo '<p><a title="'.$streditsummary.'" '.
123 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
124 ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
126 echo '</div>';
128 print_section($course, $thissection, $mods, $modnamesused);
130 if (isediting($course->id)) {
131 print_section_add_menus($course, $section, $modnames);
134 echo '</div>';
135 echo "</li>\n";
139 /// Now all the normal modules by week
140 /// Everything below uses "section" terminology - each "section" is a week.
142 $timenow = time();
143 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
144 $weekdate += 7200; // Add two hours to avoid possible DST problems
145 $section = 1;
146 $sectionmenu = array();
147 $weekofseconds = 604800;
148 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
150 $strftimedateshort = ' '.get_string('strftimedateshort');
152 while ($weekdate < $course->enddate) {
154 $nextweekdate = $weekdate + ($weekofseconds);
155 $weekday = userdate($weekdate, $strftimedateshort);
156 $endweekday = userdate($weekdate+518400, $strftimedateshort);
158 if (!empty($sections[$section])) {
159 $thissection = $sections[$section];
161 } else {
162 unset($thissection);
163 $thissection->course = $course->id; // Create a new week structure
164 $thissection->section = $section;
165 $thissection->summary = '';
166 $thissection->visible = 1;
167 if (!$thissection->id = insert_record('course_sections', $thissection)) {
168 notify('Error inserting new week!');
172 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
174 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
175 if ($showsection) {
176 $sectionmenu['week='.$section] = s("$strweek $section | $weekday - $endweekday");
178 $section++;
179 $weekdate = $nextweekdate;
180 continue;
183 if ($showsection) {
185 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
187 if (!$thissection->visible) {
188 $sectionstyle = ' hidden';
189 } else if ($currentweek) {
190 $sectionstyle = ' current';
191 } else {
192 $sectionstyle = '';
195 echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
197 // Note, 'right side' is BEFORE content.
198 echo '<div class="right side">';
200 if ($displaysection == $section) {
201 echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
202 '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
203 } else {
204 $strshowonlyweek = get_string("showonlyweek", "", $section);
205 echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
206 '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
209 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
210 if ($thissection->visible) { // Show the hide/show eye
211 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekhide.'">'.
212 '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
213 } else {
214 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekshow.'">'.
215 '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
217 if ($section > 1) { // Add a arrow to move section up
218 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.'">'.
219 '<img src="'.$CFG->pixpath.'/t/up.gif" class="icon up" alt="'.$strmoveup.'" /></a><br />';
222 if ($section < $course->numsections) { // Add a arrow to move section down
223 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.'">'.
224 '<img src="'.$CFG->pixpath.'/t/down.gif" class="icon down" alt="'.$strmovedown.'" /></a><br />';
227 echo '</div>';
229 echo '<div class="content">';
230 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
231 echo '<div class="weekdates">'.$weekday.' - '.$endweekday.' ('.get_string('notavailable').')</div>';
233 } else {
234 echo '<div class="weekdates">'.$weekday.' - '.$endweekday.'</div>';
236 echo '<div class="summary">';
237 $summaryformatoptions->noclean = true;
238 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
240 if (isediting($course->id) && 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="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
244 echo '</div>';
246 print_section($course, $thissection, $mods, $modnamesused);
248 if (isediting($course->id)) {
249 print_section_add_menus($course, $section, $modnames);
253 echo '</div>';
254 echo "</li>\n";
257 $section++;
258 $weekdate = $nextweekdate;
260 echo "</ul>\n";
262 if (!empty($sectionmenu)) {
263 echo '<div align="center" class="jumpmenu">';
264 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
265 'sectionmenu', '', get_string('jumpto'), '', '', true);
266 echo '</div>';
269 echo '</div>';
271 echo '</div>';
272 echo '<div class="clearer"></div>';